Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2954 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  [Résolu]JNI ou comment generer des erreurs

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Résolu]JNI ou comment generer des erreurs

n°1635047
Jaunes Les​ Nonnes
Ou bla dit ? Ou bla ? da !
Posté le 01-11-2007 à 11:56:13  profilanswer
 

Bonjour à tous,
 
Voilà depuis un plusieurs jours j'essaie de compiler un programme java qui utilise du code en natif mais malheureusement pas de franc succès jusqu'ici.
 
Je dispose d'une version compilée du programme, qui fonctionne parfaitement bien avec JAVA5 mais qui au contraire plante constamment avec java6. Je dispose aussi des sources de ce même programme. Voulant inclure certaines fonctions de cette application dans une autre, j'ai tout d'abord décidé de compiler et d'exécuter ces sources. Mais voilà, et bien ça ne compile pas... Donc voila comment je procède.
 
Je charge ma DLL avec le System.load

Code :
  1. System.load("/home/grfingerjava.dll" );


Et j'obtient le resultat suivant :
 
Sous JAVA6 : JDK 6

Code :
  1. java.lang.UnsatisfiedLinkError: /home/grfingerJava.dll: /home/grfingerJava.dll: invalid ELF header at java.lang.ClassLoader$NativeLibrary.load(Native Method)


Sous JAVA5 : JDK 5 Update 13

Code :
  1. Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/grfingerjava.dll: Can't load this .so (machine code=0x0) on a IA 32-bit platform
  2.         at java.lang.ClassLoader$NativeLibrary.load(Native Method)
  3.         at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
  4.         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1647)
  5.         at java.lang.Runtime.load0(Runtime.java:769)
  6.         at java.lang.System.load(System.java:968)
  7.         at com.griaule.fingerprintsdk.sample.FormMain.main(FormMain.java:121)


 
Voyant que le programme s'exécute bien sous java5 je me suis donc attarder un peu plus sur cette erreur. Google étant mon ami celui-ci m'a informé que cela pouvait provenir :
 

  • Du LD_LIBRARY_PATH                     => J'y ai ajouté la DLL, ça ne change rien, mais un petit rappel serait le bienvenu
  • D'un problème sur ma limite user => J'ai fait un petit sudo ulimit -u 15000 , ça ne change rien
  • Des LibX manquantes                    => Il me semble que tout est bien installe, néanmoins un petit rappel serait aussi le bienvenu
  • D'un problème en interne a la JVM => J'ai pas essayé de dedugger la JVM....DSL  ;)  


Je m'en remet donc en votre connaissance pour tenter de trouver une solution à ce probleme.
 
Config :
OS   : Ubuntu 7.10 Gusty Gibbon
CPU : Intel Pentium D 2.80 GHz
 
 
Merci


Message édité par Jaunes Les Nonnes le 01-11-2007 à 16:15:25

---------------
Pourquoi les religieuses au pays du soleil levant sont elles fans des beatles ?
mood
Publicité
Posté le 01-11-2007 à 11:56:13  profilanswer
 

n°1635124
Jaunes Les​ Nonnes
Ou bla dit ? Ou bla ? da !
Posté le 01-11-2007 à 16:09:11  profilanswer
 

Salutation une nouvelle fois !
 
Je viens de régler le problème, cela venait du java.library.path. Il semble que l'utilisation traditionnelle du -Djava.library.path= here is your path a quelques petits problèmes sur java5.  
 
J'ai donc utilise une Classe que j'ai nommée JavaLibraryPath ( très légitime comme nom ), dont voici le code :
 

Code :
  1. import java.io.File;
  2. import java.lang.reflect.Field;
  3. import java.util.Properties;
  4. /**  
  5. * Adds a path to the java.library.path System property  
  6. * and updates the ClassLoader. Uses reflection to allow
  7. * update to private system members. Will not work if JVM
  8. * security policy gets in the way (like in an applet).
  9. * Will not work if Sun changes the private members.
  10. * This really shouldn't be used at all...
  11. */
  12. public class JavaLibraryPath
  13. {
  14. public static void add(File path) throws Exception
  15. {
  16.  // Append the specified path to the
  17.  // existing java.library.path (if there is one already)
  18.  String newLibraryPath = System.getProperty("java.library.path" );
  19.  if (newLibraryPath == null || newLibraryPath.length() < 1)
  20.  {
  21.   newLibraryPath = path.getCanonicalPath();
  22.  }
  23.  else
  24.  {
  25.   newLibraryPath += File.pathSeparator +
  26.    path.getCanonicalPath();
  27.  }
  28.  // Reflect into java.lang.System to get the  
  29.  // static Properties reference
  30.  Field f = System.class.getDeclaredField("props" );
  31.  f.setAccessible(true);
  32.  Properties props = (Properties) f.get(null);
  33.  // replace the java.library.path with our new one
  34.  props.put("java.library.path", newLibraryPath);
  35.  // The classLoader may have already been initialized,
  36.  // so it needs to be fixed up.
  37.  // Reflect into java.lang.ClassLoader to get the  
  38.  // static String[] of user paths to native libraries
  39.  Field usr_pathsField =
  40.    ClassLoader.class.getDeclaredField("usr_paths" );
  41.  usr_pathsField.setAccessible(true);
  42.  String[] usr_paths = (String[]) usr_pathsField.get(null);
  43.  String[] newUsr_paths = new String[usr_paths == null ? 1 :
  44.   usr_paths.length + 1];
  45.  if (usr_paths != null)
  46.  {
  47.   System.arraycopy(usr_paths, 0, newUsr_paths,
  48.    0, usr_paths.length);
  49.  }
  50.  // Add the specified path to the end of a new String[]
  51.  // of user paths to native libraries
  52.  newUsr_paths[newUsr_paths.length - 1] = path.getAbsolutePath();
  53.  usr_pathsField.set(null, newUsr_paths);
  54. }
  55. }


 
Ensuite il vous suffit de créer une instance de cette classe comme suit.
 
Dans mon cas :

Code :
  1. JavaLibraryPath.add(new File("/home/Fingerprint SDK Java 2007/bin/" ));


 
De manière generale :

Code :
  1. JavaLibraryPath.add(new File("/your/libs/path/" ));


 
Et ainsi java ira chercher vos DLL dans ce repertoire.
 

Code :
  1. System.out.println("My java.library.path :" + System.getProperty("java.library.path" ));


Vous permettra de vérifier l'ajout de cette nouvelle valeur a votre "java.library.path"
 
Merci tout de même pour ceux qui ont lu le message


Message édité par Jaunes Les Nonnes le 01-11-2007 à 16:09:43

---------------
Pourquoi les religieuses au pays du soleil levant sont elles fans des beatles ?

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  [Résolu]JNI ou comment generer des erreurs

 

Sujets relatifs
Zoom sur carte vectorielle[RESOLU][SQL] message d'erreur qui n'a pa lieu d'être[RESOLU]
[RESOLU] Supprimer/fermer une fenetre ( de la mémoire )[RESOLU] probleme counter
[Résolu] Lecture dans un fichier avec GetPrivateProfileString[ RESOLU ] [ PHP ] Modification de chaines
Carte Interactive [RESOLU][Résolu]Requêtes sur Msysobjects
[Résolu] Symfony - Premier projet et configuration d'un virtualhost[Résolu] Article et image dans MySQL
Plus de sujets relatifs à : [Résolu]JNI ou comment generer des erreurs


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR