[Gdal-dev] using gdal/ogr within java-project

Christine Spietz spietz at fh-bingen.de
Mon May 29 10:45:10 EDT 2006


Hi folks,

I've finally installed OGR/GDAL1.3.2 with the java-swig-bindings on my Suse 
Linux 10.0.
(GDAL-HOME = /usr/lib/gdal/gdal-1.3.2)

Now I'm trying to use those bindings within my Java-Source-Code but first 
Test even fails:
I've built an Eclipse-Project with the libraries
- jre system library (java 1.4.2.06)
- GDAL-Home/swig/java/gdal.jar
and imported some filesystems especially:
- GDAL-Home/swig/java/org
- GDAL-Home/swig/java/apps

In GDAL-Home/swig/java/apps there are 2 "test-applications"
- gdalinfo.java
- GDALtest.java

I've tried to run one of those but getting the following error:
###
Native library load failed.
java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path
Exception in Thread "main" java.lang.UnsatisfiedLinkError: AllRegister
    at org.gdal.gdal.gdalJNI.AllRegister(Native Method)
    ....
###

So obviously the application is not able to find the gdaljni.

I wrote some little code to discover the error:

###
//output of the actual java.library.path
String props = System.getProperty("java.library.path");
System.out.println("props = "+props);
//adding the path to the *jni.so-files generated by java-swig
System.setProperty("java.library.path",props+":/usr/lib/gdal/gdal-1.3.2/swig/java/.libs");
//Error message was "java.lang.UnsatisfiedLinkError: no gdaljni in 
java.library.path"
//output of the actual gdaljni-Parameter
String gdalJNI = System.mapLibraryName("gdaljni");
System.out.println("gdaljni ="+ gdalJNI);
###

Output of the Code (integrated in main of gdalinfo):
###
props = /usr/lib/jvm/java-1.2.4-sun-1.2.4.06/jre/lib/i368/client : .... : 
/usr/lib/gdal/gdal-1.3.2/swig/java/.libs
gdaljni = libgdaljni.so
Native library load failed.
java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path
Exception in Thread "main" java.lang.UnsatisfiedLinkError: AllRegister
    at org.gdal.gdal.gdalJNI.AllRegister(Native Method)
###


Has anybody an idea
- what I have to do to run gdalinfo.java/GDALtest.java within my project?
- how to use gdal/ogr within a java-project?


regards

Christine 




More information about the Gdal-dev mailing list