2017-05-23 1 views
0

J'utilise java bibliothèque GDAL comme une dépendance à l'application Java Web avec dépendances Maven:Impossible de charger la bibliothèque native Java GDAL dans l'application web

<dependency> 
     <groupId>org.gdal</groupId> 
     <artifactId>gdal</artifactId> 
     <version>1.11.1</version> 
    </dependency> 

Il contient un fichier jar et exécute les codes natifs en C++ sous que j'ai dû installer à partir de paquets dans Centos. Toutes ces bibliothèques partagées sont installées dans

ls -l /usr/lib/java/gdal/ 
total 1380 
-rwxr-xr-x 3 root root 23288 Feb 14 2016 libgdalconstjni.so 
-rwxr-xr-x 3 root root 23288 Feb 14 2016 libgdalconstjni.so.1 
-rwxr-xr-x 3 root root 23288 Feb 14 2016 libgdalconstjni.so.1.18.4 
-rwxr-xr-x 3 root root 226696 Feb 14 2016 libgdaljni.so 
-rwxr-xr-x 3 root root 226696 Feb 14 2016 libgdaljni.so.1 
-rwxr-xr-x 3 root root 226696 Feb 14 2016 libgdaljni.so.1.18.4 
-rwxr-xr-x 3 root root 136760 Feb 14 2016 libogrjni.so 
-rwxr-xr-x 3 root root 136760 Feb 14 2016 libogrjni.so.1 
-rwxr-xr-x 3 root root 136760 Feb 14 2016 libogrjni.so.1.18.4 
-rwxr-xr-x 3 root root 73816 Feb 14 2016 libosrjni.so 
-rwxr-xr-x 3 root root 73816 Feb 14 2016 libosrjni.so.1 
-rwxr-xr-x 3 root root 73816 Feb 14 2016 libosrjni.so.1.18.4 

Cependant, l'application Web ne peut pas lier comme il a un problème de relier les bibliothèques, même si ce que je peux voir de chargeur de classe de Java est:

System.out.println(System.getProperty("java.library.path")); 
/opt/jdk1.8.0_25/jre/lib/amd64:/opt/jdk1.8.0_25/jre/lib/i386::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 

qui contient le dossier/usr/lib.

L'erreur de la GDAL java quand j'appeler une API GDAL (il ne dispose pas d'erreur si je n'invoque pas les méthodes de GDAL pour que d'autres méthodes de travail encore, l'application Web peut fonctionner normalement) est:

Caused by: java.lang.UnsatisfiedLinkError: org.gdal.osr.osrJNI.new_SpatialReference__SWIG_1()J 
at org.gdal.osr.osrJNI.new_SpatialReference__SWIG_1(Native Method) ~[gdal-1.11.1.jar:na] 
at org.gdal.osr.SpatialReference.<init>(SpatialReference.java:117) ~[gdal-1.11.1.jar:na] 

Je ne sais pas comment résoudre ce problème, j'ai essayé de trouver beaucoup de ressources mais pas d'aide car je veux le déployer en tant qu'application Web sur le serveur Tomcat. Je pourrais le faire fonctionner lors de la mise en NetBeans IDE avec option JVM

-Djava.library.path="/usr/lib/java/gdal/" 

mais je sais que ce n'est pas quelle application web peut fonctionner.

+0

Si je tente de charger un objet partagé manuellement avec: System.load ("/ usr/lib/java/GDAL/libgdalconstjni. alors"); Causée par: java.lang.UnsatisfiedLinkError: Native Library /usr/lib/java/gdal/libogrjni.so déjà chargé dans un autre classloader –

Répondre

0

je pourrais le faire avec une grande aide de ce blog http://fahdshariff.blogspot.de/2011/08/changing-java-library-path-at-runtime.html

Option 2: Add path to usr_paths 
Instead of having to re-evaluate the entire java.library.path and sun.boot.library.path as in Option 1, you can instead append your path to the usr_paths array. This is shown in the following code: 
/** 
* Adds the specified path to the java library path 
* 
* @param pathToAdd the path to add 
* @throws Exception 
*/ 
public static void addLibraryPath(String pathToAdd) throws Exception{ 
    final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths"); 
    usrPathsField.setAccessible(true); 

    //get array of paths 
    final String[] paths = (String[])usrPathsField.get(null); 

    //check if the path to add is already present 
    for(String path : paths) { 
     if(path.equals(pathToAdd)) { 
      return; 
     } 
    } 

    //add the new path 
    final String[] newPaths = Arrays.copyOf(paths, paths.length + 1); 
    newPaths[newPaths.length-1] = pathToAdd; 
    usrPathsField.set(null, newPaths); 
}