wiki:GdalOgrInJavaBuildInstructions

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

partial rewrite...

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

Apache Ant

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

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

I don't think ANT is really needed, perhaps remove this step...

Set up environment variables

  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.
  1. Do the same for PATH. Ensure that "<java-dir>\bin" and "<ant-dir>\bin" are included in PATH.

Compile GDAL

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

Adjust the SWIG macro in <gdal-dir>\nmake.opt to point to C:\OSGeo4W\apps\swigwin\swig.exe if using the OSGeo4W provided version of swig.

Otherwise build GDAL normally.

Configure Swig Bindings

In <gdal-dir>\swig\java, edit the java.opt file pointing it to your correct JDK location. Also update the JAVA_INCLUDE to reference the win32 directory.

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
  1. In <gdal-dir>\swig, run "nmake -f makefile.vc java".
  1. Move the following files from <gdal-dir>\swig\java to <gdal-dir>\swig\java\apps:
    - gdalconstjni.dll
    - gdaljni.dll
    - ogrjni.dll
    - osrjni.dll
    
  1. Copy the following files from <geos-dir>\source to <gdal-dir>\swig\java\apps:
    - geos.dll
    - geos_c.dll
    
  1. Check that <gdal-dir>\swig\java\gdal.jar has been created. If it has not been created, run “ant” in the <gdal-dir>\swig\java directory to compile the Java sources into gdal.jar.

8. Compile and run Java applications

  1. Place a Java source file in <gdal-dir>\swig\java\apps.
  1. Open a command line window (i.e., "cmd") and change directory to <gdal-dir>\swig\java\apps.
  1. To compile a Java file, enter "javac <file>.java".
  1. To launch a Java application, enter "java <class>".
Note: See TracWiki for help on using the wiki.