wiki:GdalOgrInJavaBuildInstructions

Version 2 (modified by allanx13, 16 years ago) ( diff )

--

Build Instructions for GDAL/OGR In Java (Windows)

NOTES

(1) These instructions were written in January 2008.

(2) GEOS is included here, but it is not necessary.

(3) MS Visual C++ is required for compiling various packages. Version 7 has been tested and has no problems; older/newer versions should work, but have not been tested.

(4) Version numbers in parentheses are the latest versions available for each given package (except for packages where a specific version is required).

(5) <geos-dir> refers to the directory where GEOS is installed. <gdal-dir> refers to the directory where GDAL is installed. <java-dir> refers to the directory where Java is installed. <ant-dir> refers to the directory where Apache Ant is installed.

1. Compile GEOS 2.2.3

http://geos.refractions.net

I couldn't get the latest version, 3.0.0, to compile on my PC with MS VC7; however, there are project files for MS VC8 available that could be tried. However, version 2.2.3 was good enough for what I needed.

  1. Download http://svn.osgeo.org/geos/trunk/source/headers/geos/version.h.vc and place it in <geos-dir>\source\headers\geos. Edit the following lines:
    #define GEOS_VERSION_MAJOR 3	- change 3 to 2
    #define GEOS_VERSION_MINOR 0	- change 0 to 2
    #define GEOS_VERSION_PATCH 0rc4	- change 0rc4 to 2
    #define GEOS_VERSION "3.0.0rc4"	- change 3.0.0rc4 to 2.2.3
    
  1. Rename <geos-dir>\source\capi\geos_c.h.in to geos_c.h.vc.
  1. Run MSVC's vcvars32.bat
  1. In the "source" directory, run "nmake -f makefile.vc"

2. Install the latest version of SWIG (1.3.33)

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

A Windows version with a pre-built executable is available, so compiling isn't necessary.

3. Install the latest version of the Java SE Development Kit (1.6.0_03)

http://java.sun.com/javase/downloads/index.jsp

4. Install the latest version of Apache Ant (1.7.0)

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

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

5. 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.

6. Compile GDAL 1.4.4 with GEOS

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

GDAL 1.5's Java bindings are orphaned and are believed to be broken, so we'll stick with 1.4.4 for now.

  1. Open <gdal-dir>\nmake.opt and make the following changes:
    - Change the value of SWIG to the location of swig.exe (ex. SWIG = c:\progra~1\swigwin-1.3.33\swig.exe).
    - Uncomment the GEOS_CFLAGS and GEOS_LIB lines.
    - Change the value of GEOS_CFLAGS to the source/capi directory in the GEOS installation (ex. GEOS_CFLAGS = -Ic:\geos-2.2.3\source\capi -DHAVE_GEOS).
    - Change the value of GEOS_LIB to the location of geos_c_i.lib (ex. GEOS_LIB = c:\geos-2.2.3\source\geos_c_i.lib).
    
  1. Run MSVC's vcvars32.bat
  1. In <gdal-dir>, run "nmake -f makefile.vc".

7. Compile GDAL's Java bindings

  1. Run MSVC's vcvars32.bat
  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.