GRASS and Java

From GRASS-Wiki
Revision as of 13:36, 30 December 2011 by MilenaN (talk | contribs) (Reverted edits by Reverse22 (talk) to last revision by Neteler)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

vtk-grass-bridge with JAVA bindings

The vtk-grass-bridge main page

Short introduction how to compile the vtk-grass-bridge:


The Java module v_sample_rast:

Calling GRASS from JAVA


       public String run(String[] cmd)  {
                       Process p1=rt.exec(cmd, env);

and use:{"", "map=roads"});



It seems that calling grass in JAVA by using java.Lang.Runtime.exec() can be implemented easily in Linux platform (tested successfully on Ubuntu 9.10).

First install the grass use the apt-get:

 sudo apt-get install grass  # it will install the latest stable version

After the installation completed you can:

 #Test it in the terminal without JAVA (make sure that you have a GRASS database installed):

Open a terminal and enter:


The following the instruction in the screen or check here.

Test the environment settings

Test using GRASS command directly in the terminal:

Set the environment (we assume GRASS being installed under /usr/lib/grass64):

export GISBASE=/usr/lib/grass64
export GISRC=/home/kk/gisrc
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts

Then try some GRASS command directly, for example:


Now call GRASS in JAVA if the above test 2 passed.

Just use the Runtime.getRuntime.exec(String cmd,String[] env):

String cmd="g.version";

String[] exe = { "bash", "-c", cmd };
String[] env={"GISBASE=..","GISRC="".......};  // the environment variables which you set in the step 2.