wiki:GdalOgrInJavaBuildInstructions

Version 7 (modified by warmerdam, 13 years ago) ( diff )

--

Build Instructions for GDAL/OGR In Java (Windows)

Install SWIG

http://www.swig.org/download.html

Install an appropriate version of SWIG for windows. GDAL/OGR's Java bindings correct operation are fairly sensitive to the version of SWIG used. Version 1.3.39 is appropriate for GDAL/OGR 1.8.0. A Windows version with a pre-built executable is available, so compiling isn't necessary.

OSGeo4W has a "swig" package which will install a suitable version of swig in C:\OSGeo4W\apps\swigwin.

Install the latest version of the Java SE Development Kit

Make sure you are getting the "JDK", not just the runtime environment. The "SE" (standard edition?) is fine, no need for "EE" (enterprise edition).

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Apache Ant

http://ant.apache.org/bindownload.cgi

Binary distributions are available, so compiling isn't necessary.

Download and Configure GDAL

http://trac.osgeo.org/gdal/wiki/DownloadSource

Follow normal steps to configure GDAL by modifying <gdal-dir>\nmake.opt. In addition to normal steps ensure that the SWIG, JAVA and ANT related definitions are set appropriately. Perhaps something like:

JAVA_HOME = "C:\Program Files\Java\jdk1.6.0_23"
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\win32

ANT_HOME=C:\apache-ant-1.8.2

SWIG=C:\OSGeo4W\apps\swigwin\swig.exe

Compile GDAL

See BuildingOnWindows for details on configuring and building GDAL on windows.

nmake /f makefile.vc

Build Java Bindings

This step will run SWIG to generate the Java bindings, use nmake/cl.exe to build the C++ side of the Java bindings and ANT/javac to compile the java side of the bindings.

{{ cd swig nmake /f makefile.vc java }}}

The result, in the gdal/swig/java directory, should be the following files: gdal.jar, gdalconstjni.dll, gdaljni.dll, ogrjni.dll and osrjni.dll.

Test Sample Application

First, ensure that java.exe and javac.exe are available in your path and that any DLLs on which GDAL depends are in your path.

cd swig\java\apps
copy ..\..\..\*.dll
copy ..\*.dll
javac -classpath ..\gdal.jar;. gdalinfo.java
java -classpath ..\gdal.jar;. gdalinfo

You should get a usage message, or add a filename to the end of the last command to see a gdalinfo style report on the file.

Install components

The jni dll's can be installed somewhere appropriate, often wherever the main GDAL DLL (ie gdal18.dll) goes.

The gdal.jar will need to be in the class path.

CLASSPATH

It may be desirable to modify the CLASSPATH globally. This can be done like this:

  1. In the Control Panel, open up System. Switch to the Advanced tab and click on Environmental Variables.
  1. In the System Variables pane, look for CLASSPATH. If it exists, click on "Edit" and ensure that "." and "..\gdal.jar" are included. Individual items are separated by colons. If CLASSPATH does not exist, click on "New" and add CLASSPATH with the same two locations.
Note: See TracWiki for help on using the wiki.