Discussion:
[gdal-dev] Native library load failed while using gdal maven dependency - UnsatisfiedLinkError
ssaniev
2016-02-09 16:28:33 UTC
Permalink
Hey guys,

First time GDAL user here.

We are trying to load shapefiles into postgresql DB, and were able to do so
with GDAL ogr2ogr CLI utility.
Following cmd works via cmd:
ogr2ogr -f PostgreSQL PG:"host='hostName' port='5432' user='userName'
dbname='dbName' password='aPassword'" shapeFileName.shp


*Next step is to accomplish this in java with GDAL bindings. *

There is a maven dependency for gdal which we included in our pom.xml:
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>2.0.0</version>
</dependency>


*We import and simply want to output the version of gdal in java: *

import org.gdal.gdal.gdal;

public class ShapeFileWorker {
public void process(String fileName, String hostAddress) {
gdal.VersionInfo()
}
}


*While trying to use gdal library in our java class, we are getting the
following error: *
java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path


The development project is in SPRING, and Eclipse IDE.

After reading many online gdal discussions, I have added GDAL_DATA and
LD_LIBRARY_PATH variables.

But since we are using gdal maven dependency, we shouldn't need them.

Anyone could point us in the right direction?



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Native-library-load-failed-while-using-gdal-maven-dependency-UnsatisfiedLinkError-tp5249728.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
Justin Deoliveira
2016-02-09 16:55:43 UTC
Permalink
Hi,

Have you set the java.library.path system property to the location of the
gdal libraries on the system? The gdal jar doesn’t contain any of the
native libraries, just the java parts.

I’ve found that usually I do need to set LD_LIBRARY_PATH to include the
location of the gdal libraries, and the location of any libraries that it
is linked to.

For example if you I had the native GDAL libraries in /usr/local/lib I
would set up my java IDE as follows:

- Set the environment variable LD_LIBRARY_PATH (linux) or DYLD_LIBRARY_PATH
(osx) to /usr/local/lib
- Add the java system property “-Djava.library.path=/usr/local/lib”

And that usually does the trick for me. Hope that helps.

-Justin
Post by ssaniev
Hey guys,
First time GDAL user here.
We are trying to load shapefiles into postgresql DB, and were able to do so
with GDAL ogr2ogr CLI utility.
ogr2ogr -f PostgreSQL PG:"host='hostName' port='5432' user='userName'
dbname='dbName' password='aPassword'" shapeFileName.shp
*Next step is to accomplish this in java with GDAL bindings. *
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>2.0.0</version>
</dependency>
*We import and simply want to output the version of gdal in java: *
import org.gdal.gdal.gdal;
public class ShapeFileWorker {
public void process(String fileName, String hostAddress) {
gdal.VersionInfo()
}
}
*While trying to use gdal library in our java class, we are getting the
following error: *
java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path
The development project is in SPRING, and Eclipse IDE.
After reading many online gdal discussions, I have added GDAL_DATA and
LD_LIBRARY_PATH variables.
But since we are using gdal maven dependency, we shouldn't need them.
Anyone could point us in the right direction?
--
http://osgeo-org.1560.x6.nabble.com/Native-library-load-failed-while-using-gdal-maven-dependency-UnsatisfiedLinkError-tp5249728.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
_______________________________________________
gdal-dev mailing list
http://lists.osgeo.org/mailman/listinfo/gdal-dev
ssaniev
2016-02-09 19:46:50 UTC
Permalink
Hi Justin,

Coding in java Windows7/Eclipse/spring/maven.

*As told before, added dependency to pom, and see the gdal-2.0.0.jar in
maven dependencies and able to import to my java class.*
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>2.0.0</version>
</dependency>


I downloaded the libraries from here:
http://download.gisinternals.com/sdk/downloads/release-1800-x64-gdal-1-11-3-mapserver-6-4-2.zip

unzippped... and added the both paths below to my environment PATH variable:
..\Downloads\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin
..\Downloads\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin\gdal\java

Created another environment variable
GDAL_DATA=..\Downloads\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin\gdal-data

Inside Eclipse, added a VM argument to my project runtume:
-Djava.library.path="..\workspace\GISDataDirectory\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin\gdal\java\;${env_var:PATH}"



*And after all this, I am getting a different related error:*

Native library load failed.
java.lang.UnsatisfiedLinkError:
..\workspace\GISDataDirectory\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin\gdal\java\gdaljni.dll:
The specified procedure could not be found

nested exception is java.lang.UnsatisfiedLinkError:
org.gdal.gdal.gdalJNI.VersionInfo__SWIG_1()Ljava/lang/String;] with root
cause


What am I missing here?




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Native-library-load-failed-while-using-gdal-maven-dependency-UnsatisfiedLinkError-tp5249728p5249767.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
Justin Deoliveira
2016-02-09 20:27:04 UTC
Permalink
Looks like you have everything configured properly. I have seen reports
from users having issue with using a gdal jar compiled on a different
system. I’ve never seen that personally but from what I understand the
solution in that case was to just compile the java (and the rest of the
gdal libs) themselves locally.
Post by ssaniev
Hi Justin,
Coding in java Windows7/Eclipse/spring/maven.
*As told before, added dependency to pom, and see the gdal-2.0.0.jar in
maven dependencies and able to import to my java class.*
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>2.0.0</version>
</dependency>
http://download.gisinternals.com/sdk/downloads/release-1800-x64-gdal-1-11-3-mapserver-6-4-2.zip
..\Downloads\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin
..\Downloads\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin\gdal\java
Created another environment variable
GDAL_DATA=..\Downloads\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin\gdal-data
-Djava.library.path="..\workspace\GISDataDirectory\release-1800-x64-gdal-1-11-3-mapserver-6-4-2\bin\gdal\java\;${env_var:PATH}"
*And after all this, I am getting a different related error:*
Native library load failed.
The specified procedure could not be found
org.gdal.gdal.gdalJNI.VersionInfo__SWIG_1()Ljava/lang/String;] with root
cause
What am I missing here?
--
http://osgeo-org.1560.x6.nabble.com/Native-library-load-failed-while-using-gdal-maven-dependency-UnsatisfiedLinkError-tp5249728p5249767.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
_______________________________________________
gdal-dev mailing list
http://lists.osgeo.org/mailman/listinfo/gdal-dev
ssaniev
2016-02-09 20:23:46 UTC
Permalink
Thanks. Will be looking into that soon. Will report back here if it works.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Native-library-load-failed-while-using-gdal-maven-dependency-UnsatisfiedLinkError-tp5249728p5249772.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
ssaniev
2016-02-10 14:29:18 UTC
Permalink
So the solution for using gdal bindings in java was to install the proper
version which came with all the dll's and simply using the jar from the
maven repo.

I installed core gdal installer in windows, and set my environment
variables, and gdal jar started to work correctly in my maven project.

Installer used:
http://www.gisinternals.com/release.php
gdal-111-1800-x64-core.msi Generic installer for the GDAL core components
http://download.gisinternals.com/sdk/downloads/release-1800-x64-gdal-1-11-3-mapserver-6-4-2/gdal-111-1800-x64-core.msi

maven dependency:
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>1.11.2</version>
</dependency>


Environment variables:
GDAL_BIN=C:\Program Files\GDAL
GDAL_DATA=C:\Program Files\GDAL\gdal-data
GDAL_DRIVER=C:\Program Files\GDAL\gdalplugins

Also in eclipse, passing in as a VM argument to find needed *.dll-s :
-Djava.library.path="C:\Program Files\GDAL;${env_var:PATH}"

---------------------------------------

So code works at this point.

import org.gdal.gdal.gdal;
import org.gdal.ogr.ogr;

public class ShapeFileWorker {
ogr.RegisterAll();
gdal.AllRegister();
gdal.VersionInfo();
}



Pulled a lot of hairs until now, but finally works.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Native-library-load-failed-while-using-gdal-maven-dependency-UnsatisfiedLinkError-tp5249728p5249930.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.

Loading...