Changes between Version 8 and Version 9 of GdalOgrInJavaBuildInstructionsUnix


Ignore:
Timestamp:
Nov 27, 2023, 5:13:37 AM (5 months ago)
Author:
Even Rouault
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GdalOgrInJavaBuildInstructionsUnix

    v8 v9  
    1 = Building GDAL/OGR Java Bindings on Linux/Unix/MinGW =
    2 
    3 Tested with GDAL 1.5.2, 1.7.0 and 1.9.2.
    4 
    5 == Configure and Build GDAL ==
    6 
    7 You need swig in the path.
    8 
    9 I found I had to configure GDAL --without-libtool to get the java bindings to build.
    10 
    11 Note : with GDAL 1.7.0, this restriction is no longer necessary. libtool building should work just fine.
    12 
    13 == Update java.opt ==
    14 
    15 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.  ant is assumed to be in the path.
    16 
    17 {{{
    18 JAVA_HOME = /home/warmerda/pkg/jdk1.6.0_10
    19 JAVADOC=$(JAVA_HOME)/bin/javadoc
    20 JAVAC=$(JAVA_HOME)/bin/javac
    21 JAVA=$(JAVA_HOME)/bin/java
    22 JAR=$(JAVA_HOME)/bin/jar
    23 JAVA_INCLUDE=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
    24 }}}
    25 
    26 === OS X Leopard ===
    27 
    28 See this ticket http://trac.osgeo.org/gdal/ticket/2401 for a patch and java.opt for building the java bindings on Leopard
    29 
    30 === Win32 MinGW ===
    31 
    32 Tested with GDAL 1.7.0. Building the Java bindings under MinGW is possible but requires a bit of patching :
    33 
    34 * Update the JAVA_HOME variable in gdal/swig/java/java.opt and change the JAVA_INCLUDE variable to the following value :
    35 {{{
    36 JAVA_INCLUDE=-I$(JAVA_HOME)/include -I.
    37 }}}
    38  
    39 * in swig/java/GNUmakefile, we ensure that the name of the DLLs are not prefixed by lib, by changing the 'JAVA_MODULES= libgdaljni.$(SO_EXT)...' and '$(JAVA_MODULES): %jni.$(SO_EXT)...' lines to be
    40 
    41 {{{
    42 JAVA_MODULES = gdaljni.$(SO_EXT) ogrjni.$(SO_EXT) gdalconstjni.$(SO_EXT) osrjni.$(SO_EXT)
    43 }}}
    44 
    45 and
    46 
    47 {{{
    48 $(JAVA_MODULES): %jni.$(SO_EXT): %_wrap.$(OBJ_EXT)
    49 }}}
    50 
    51 * Create a jni_md.h file in gdal/swig/java directory with the following content that ensures thanks to the empty JNICALL that the symbols in the *jni.dll have the proper decorations
    52 
    53 {{{
    54 #ifndef _GDAL_JNI_MD_H_
    55 #define _GDAL_JNI_MD_H_
    56 
    57 #define JNIEXPORT __declspec(dllexport)
    58 #define JNIIMPORT __declspec(dllimport)
    59 #define JNICALL
    60 
    61 typedef long jint;
    62 typedef __int64 jlong;
    63 typedef signed char jbyte;
    64 
    65 #endif
    66 }}}
    67 
    68 Then run make from gdal/swig/java.  and the GDAL DLL is in the path, "java -cp "gdal.jar;build/apps" gdalinfo" should work.
    69 
    70 == Run the java build ==
    71 
    72 Do a "make" in gdal/swig/java.
    73 
    74 You should see a bunch of stuff, possible ending with this:
    75 
    76 {{{
    77 cp ./.libs/*.so ./
    78 cp: cannot stat `./.libs/*.so': No such file or directory
    79 make: [build] Error 1 (ignored)
    80 ant
    81 Buildfile: build.xml
    82 
    83 compile:
    84     [javac] Compiling 33 source files to /wrk/home/warmerda/wrk/gdal-1.5.2/swig/java/build/classes
    85      [echo] compilation complete
    86 
    87 archive:
    88       [jar] Building jar: /wrk/home/warmerda/wrk/gdal-1.5.2/swig/java/gdal.jar
    89 
    90 BUILD SUCCESSFUL
    91 Total time: 2 seconds
    92 }}}
    93 
    94 Don't worry about the ./.libs/*.so error.  That appears to be something that would apply with libtool builds.
    95 
    96 == Running something ==
    97 
    98 While still in gdal/swig/java try:
    99 
    100 {{{
    101 javac apps/gdalinfo.java
    102 setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:`pwd`:path_to_directory_where_libgdal_so
    103 java -classpath `pwd`/gdal.jar:`pwd`:`pwd`/apps gdalinfo
    104 }}}
    105 
    106 Starting with GDAL 1.7.0, the utilities are automatically built in the swig/java/build/apps directory. So after building, you can just do
    107 
    108 {{{
    109 setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:`pwd`:path_to_directory_where_libgdal_so
    110 java -classpath `pwd`/gdal.jar:`pwd`:`pwd`/build/apps gdalinfo
    111 }}}
    112 
    113 With luck you will see the gdalinfo usage message.
    114 
    115 To deploy you need gdal.jar in your class path, the 4 .so files (libgdalconstjni.so, libgdaljni.so, libogrjni.so and libosrjni.so) and libgdal.so in your shared library path.
    116 
     1See https://gdal.org/api/java/index.html