wiki:GdalOgrInJavaBuildInstructionsUnix

Version 5 (modified by Even Rouault, 15 years ago) ( diff )

--

Building GDAL/OGR Java Bindings on Linux/Unix

Tested with gdal-1.5.2.

Configure and Build GDAL

I found I had to configure GDAL --without-libtool to get the java bindings to build.

Note : with GDAL 1.7.0, this restriction is no longer necessary. libtool building should work just fine.

Update java.opt

Replace/Create gdal/swig/java/java.opt with an appropriate local version. Make sure the windows backslashes are turned to forward slashes, and point to your local Java SDK. The ANT_HOME isn't used on linux where it is apparently assumed ant will be in the path.

JAVA_HOME = /home/warmerda/pkg/jdk1.6.0_10
#ANT_HOME=c:\programmi\apache-ant-1.7.0
JAVADOC=$(JAVA_HOME)/bin/javadoc
JAVAC=$(JAVA_HOME)/bin/javac
JAVA=$(JAVA_HOME)/bin/java
JAR=$(JAVA_HOME)/bin/jar
JAVA_INCLUDE=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux

OS X Leopard

See this ticket http://trac.osgeo.org/gdal/ticket/2401 for a patch and java.opt for building the java bindings on Leopard

Run the java build

Do a "make" in gdal/swig/java.

You should see a bunch of stuff, possible ending with this:

cp ./.libs/*.so ./
cp: cannot stat `./.libs/*.so': No such file or directory
make: [build] Error 1 (ignored)
ant
Buildfile: build.xml

compile:
    [javac] Compiling 33 source files to /wrk/home/warmerda/wrk/gdal-1.5.2/swig/java/build/classes
     [echo] compilation complete

archive:
      [jar] Building jar: /wrk/home/warmerda/wrk/gdal-1.5.2/swig/java/gdal.jar

BUILD SUCCESSFUL
Total time: 2 seconds

Don't worry about the ./.libs/*.so error. That appears to be something that would apply with libtool builds.

Running something

While still in gdal/swig/java try:

javac apps/gdalinfo.java
setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:`pwd`
java -classpath `pwd`/gdal.jar:`pwd`:`pwd`/apps gdalinfo

With luck you will see the gdalinfo usage message.

To deploy you need gdal.jar in your class path, and the four .so files (libgdalconstjni.so, libgdaljni.so, libogrjni.so and libosrjni.so) in your shared library path.

Note: See TracWiki for help on using the wiki.