7
votes

I want to package GDAL and its JAVA binding into a SWT plug-in. (P.S. GDAL use swig to generate Java binding)

I have all necessary native libraries and want to pack them into my Eclipse plug-in to let other people use it without installing GDAL on their computer.

The problem is that the JAVA Binding (or native lib itself) will lookup necessary native libraries from PATH (Window) or LD_LIBRARY_PATH (Linux) instead looking up those libs in a relative location. Furthermore, GDAL will look up some necessary geo definition data from the environment variable GDAL_DATA as well.

How can I solve those two problems to make a portable SWT plug-in? 1) package platform specific native libs 2) some environment variable look-up

It seems that eclipse cannot resolve dependent libs without having PATH set. Bundle-NativeCode (see below) did not work.

If I try to directly call System.Library("SomethingNotExist") in my plugin; then I get

java.lang.UnsatisfiedLinkError: no SomethingNotExist in java.library.path

If I call System.Library("SomethingDoesExist") in my plugin, then I get

java.lang.UnsatisfiedLinkError: SomethingDoesExist.dll: Can't find dependent libraries

The file structure in my plug-in

org.gdal/
   + src/
   + nativelib/
      + linux32/
        + ...
      + linux32/
        + ...
      + win32/
        + ...
      + win64/
        + ...
   + META-INF
      + MANIFEST.MF
   + gdal-data/
   + gdal.jar
   + build.properties

The build.properties for this Plug-in

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               gdal.jar,\
               gdal-data/,\
               nativelib/

The Manifest for this Plug-in

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: GDAL
Bundle-SymbolicName: org.gdal
Bundle-Version: 1.8.1
Bundle-NativeCode: 
 nativelib/linux32/libgdal.so;
 nativelib/linux32/libgdalconstjni.so;
 nativelib/linux32/libgdaljni.so;
 nativelib/linux32/libogrjni.so;
 nativelib/linux32/libosrjni.so;
 osname=Linux; processor=x86,
 nativelib/linux64/libgdal.so;
 nativelib/linux64/libgdalconstjni.so;
 nativelib/linux64/libgdaljni.so;
 nativelib/linux64/libogrjni.so;
 nativelib/linux64/libosrjni.so;
 osname=Linux; processor=x86_64,
 nativelib/win32/gdal18.dll;
 nativelib/win32/gdalconstjni.dll;
 nativelib/win32/gdaljni.dll;
 nativelib/win32/geos_c.dll;
 nativelib/win32/iconv.dll;
 nativelib/win32/libcurl.dll;
 nativelib/win32/libeay32.dll;
 nativelib/win32/libexpat.dll;
 nativelib/win32/libmysql.dll;
 nativelib/win32/libpq.dll;
 nativelib/win32/libxml2.dll;
 nativelib/win32/ogrjni.dll;
 nativelib/win32/openjpeg.dll;
 nativelib/win32/osrjni.dll;
 nativelib/win32/pdflib.dll;
 nativelib/win32/proj.dll;
 nativelib/win32/spatialite.dll;
 nativelib/win32/sqlite3.dll;
 nativelib/win32/ssleay32.dll;
 nativelib/win32/xerces-c_2_8.dll;
 nativelib/win32/zlib1.dll;
 osname=win32; processor=x86,
 nativelib/win64/ogrjni.dll;
 nativelib/win64/gdal18.dll;
 nativelib/win64/xerces-c_2_8.dll;
 nativelib/win64/libexpat.dll;
 nativelib/win64/libpq.dll;
 nativelib/win64/spatialite.dll;
 nativelib/win64/libmysql.dll;    
 nativelib/win64/geos_c.dll;
 nativelib/win64/libcurl.dll;
 nativelib/win64/openjpeg.dll; 
 nativelib/win64/iconv.dll; 
 nativelib/win64/libeay32.dll;
 nativelib/win64/gdaljni.dll;
 nativelib/win64/osrjni.dll; 
 nativelib/win64/gdalconstjni.dll; 
 nativelib/win64/libxml2.dll; 
 nativelib/win64/pdflib.dll;
 nativelib/win64/proj.dll;
 nativelib/win64/sqlite3.dll;
 nativelib/win64/ssleay32.dll;
 nativelib/win64/zlib1.dll; 
 osname=win32; processor=x86_64
Bundle-ClassPath: gdal.jar,
 .,
 gdal-data/
Export-Package: org.gdal,
 org.gdal.gdal,
 org.gdal.gdalconst,
 org.gdal.ogr,
 org.gdal.osr
Bundle-RequiredExecutionEnvironment: JavaSE-1.6

1
What exactly is the problem (what errors are reported by who)? OSGi will load your DLLs from your plugin according to Bundle-NativeCode section, so JAVA Binding (or native lib itself) will lookup necessary native libraries from PATH is not the case.Martti Käärik
@Martti: really? I think the native code tries to load relevant libs from PATH and looks up some config data from other defined environment variable path. Error Message: [[Native library load failed. java.lang.UnsatisfiedLinkError: ogrjni.dll: Can't find dependent libraries]]rnd_nr_gen
Yes, native libs are loading from PATH. The point I was trying to make is that this has nothing to do with Eclipse nor Java, but normal lib resolving of any program.Martti Käärik
Does it work if you load all necessary libs from Java code and won't rely on the "assembly resolver" of native code?Martti Käärik
No, I mean in the code: System.loadLibrary("LibC"); System.loadLibrary("LibB"); System.loadLibrary("LibA");Martti Käärik

1 Answers

0
votes

For the environment issue of GDAL in Java

use gdal.SetConfigOption

http://osgeo-org.1560.n6.nabble.com/gdal-dev-GDAL-DATA-td3744017.html

To set GDAL_DATA with the folder which can be read from a plugin bundle.

http://www.vogella.de/blog/2010/07/06/reading-resources-from-plugin/