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

  FORUM HardWare.fr
  Programmation
  Java

  Webservices et JNI [resolu]

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Webservices et JNI [resolu]

n°1558787
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 11:59:05  profilanswer
 

'hello
 
J'essaie de créer un service web qui fait appel à une biblio native.
J'utilise netbeans et tomcat et voici mon code:  
 

Code :
  1. package monpak;
  2. import javax.jws.WebMethod;
  3. import javax.jws.WebService;
  4. @WebService()
  5. public class jscp2asc_ws {
  6.     /**
  7.      * Web service operation
  8.      */
  9.     @WebMethod
  10.     public String faire() {
  11.        
  12.         String dossier = new String("C:\\Program Files\\netbeans-5.5\\enterprise3\\apache-tomcat-5.5.17\\temp\\" );
  13.                  
  14.         procede(dossier,"fichier" );
  15.         return "you hou ";
  16.     }
  17.    
  18.     @WebMethod
  19.     private native void procede(String dossier, String fichier);
  20.    
  21.     static {
  22.                 System.loadLibrary("maLib" );
  23.     }
  24. }


 
Le soucis se fait au moment de l'appel à la lib.

Citation :


GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) com.sun.xml.ws.transport.http.servlet.WSServletContextListener
java.lang.UnsatisfiedLinkError: Native Library C:\Program Files\netbeans-5.5\enterprise3\apache-tomcat-5.5.17\common\lib\maLib.dll already loaded in another classloader
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1716)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)


 
J'ai pourtant suivis les conseils de tomcat, c'est à dire mettre la lib dans $catalina_home\common\lib\
 
Quelqu'un as une idée ?
 
D'avance merci


Message édité par negatifman le 11-05-2007 à 17:13:26
mood
Publicité
Posté le 11-05-2007 à 11:59:05  profilanswer
 

n°1558907
yaltar
Posté le 11-05-2007 à 14:33:57  profilanswer
 

Bonjour,
je dirais que le fait d'avoir mis la librairie dans :  
 $catalina_home\common\lib\  
fait que cette librairie est chargée au démarrage du serveur tomcat (donc pas le classpath de tomcat).
 
L'appel donc de : System.loadLibrary("maLib" );
provoque une erreur car cette lib a déjà été chargée.
 
Je déduis cela du message d'erreur, en espérant pouvoir aider

n°1558922
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 14:52:24  profilanswer
 

Merci pour ton aide yaltar.  
 
Donc, si j'enlève le System.loadLibrary, voici ce qu'il ce passe :  
le servlet se déploie mais je peux lire dans mon client une exception soap :  

Citation :

javax.xml.ws.soap.SOAPFaultException: Unknown fault type:class java.lang.UnsatisfiedLinkError at com.sun.xml.internal.ws.encoding.soap.ClientEncoderDecoder.toMessageInfo(ClientEncoderDecoder.java:86) at


 
 
Voici pourquoi j'ai mis ma lib dans le dossier common\lib :  

Citation :


I'm encountering classloader problems when using JNI under Tomcat
 
The important thing to know about using JNI under Tomcat is that one cannot place the native libraries OR their JNI interfaces under the WEB-INF/lib or WEB-INF/classes directories of a web application and expect to be able to reload the webapp without restarting the server. The class that calls System.loadLibrary(String) must be loaded by a classloader that is not affected by reloading the web application itself.
 
Thus, if you have JNI code that follows the convention of including a static initilaizer like this:
 
class FooWrapper {
    static {
        System.loadLibrary("foo" );
    }
 
    native void doFoo();
  }
 
then both this class and the shared library should be placed in the $CATALINA_HOME/shared/lib directory.
 
Note that under Windows, you'll also need to make sure that the library is in the java.library.path. Either add %CATALINA_HOME%\shared\lib to your Windows PATH environment variable, or place the DLL files in another location that is currently on the java.library.path. There may be a similar requirement for UNIX based system (I haven't checked), in which case you'd also have to add $CATALINA_HOME/shared/lib to the PATH environment variable. (Note: I'm not the original author of this entry.)
 
The symptom of this problem that I encountered looked something like this -
 
   java.lang.UnsatisfiedLinkError: Native Library WEB-INF/lib/libfoo.so already loaded in another classloader  
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1525)  
 
If the UnsatisfiedLinkError is intermittent, it may be related to Tomcat's default session manager. It restored previous sessions at startup. One of those objects may load the JNI library. Try stopping the Tomcat JVM, deleting the SESSIONS.ser file, then starting Tomcat. You may consider changing the session persistence manager at this time.  


http://wiki.apache.org/tomcat/HowT [...] 66b561139d

n°1558962
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 15:22:42  profilanswer
 

En lisant de plus près je me suis rendu compte que :  

Citation :

then both this class and the shared library should be placed in the $CATALINA_HOME/shared/lib directory.


 
Donc je place ma classe compilée avec ma lib dans le dossier lib :  

Code :
  1. package monpak;;
  2. import java.lang.String;
  3. public class jscp2 {
  4.     static {
  5.         System.loadLibrary("myLib" );
  6.     }
  7.  
  8.     public jscp2() {
  9.     }
  10.    
  11.     public native void procede(String dossier, String fichier);
  12.    
  13. }


 
Mais le soucis, c'est que ma classe "service web" ne veut plus compiler car ne trouve pas la classe ci-dessus.
 
La question: y'a-t-il quelque chose de similaire au #include en java ? (sachant que mes deux classes sont du même package)

n°1558967
yaltar
Posté le 11-05-2007 à 15:27:19  profilanswer
 

la notion de include, correspond à l'instruction 'import'
 
Ceci étant, as tu mis t'a classe directement sous shared/lib ? ou en respectant le package, à savoir : shared/lib/monpak/

n°1558969
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 15:33:38  profilanswer
 

oui oui tout a fait.
 
Netbeans me dit  

Citation :


cannot find symbol
symbol  : class jscp2


 
Alors il me propose d'importer package monpak.jscp2. Ca apporte rien.

n°1558977
yaltar
Posté le 11-05-2007 à 15:42:55  profilanswer
 

Tu veux dire que meme avec l'import ca met toujours l'erreur dans netbean?

n°1558979
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 15:44:29  profilanswer
 

Finalement, j'ai pris le jar et dans netbeans j'ai fais ajouter une lib et là j'ai plus d'erreurs.
 
Quelques bugs toujours, mais ça viens de ma partie jni je pense.
 
Merci beaucoup pour ton aide yaltar. Ca faisait plusieurs jours que j'étais coincé là dessus.

n°1558983
yaltar
Posté le 11-05-2007 à 15:48:46  profilanswer
 

Ha ben de rien si ca t'a débloqué c'est tant mieux.
Bon courage pour la suite

n°1559004
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 16:12:11  profilanswer
 

Bon et bien, j'ai parlé trop vite :/
 

Citation :

java.lang.NoClassDefFoundError: Could not initialize class monpak.jscp2


mood
Publicité
Posté le 11-05-2007 à 16:12:11  profilanswer
 

n°1559010
yaltar
Posté le 11-05-2007 à 16:21:14  profilanswer
 

Je suppose que ce message d'erreur vient de tomcat ...
Donc il trouve pas ta class jscp2.
Tu l'as mis sous quel forme dans shared/lib

n°1559022
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 16:29:49  profilanswer
 

Je l'ai mis en .jar

n°1559027
yaltar
Posté le 11-05-2007 à 16:34:42  profilanswer
 

Bon alors j'avoue que la j'ai un doute, je vais peut etre dire une bétise.
Ne faudrait-il pas spécifier dans le CLASSPATH de tomcat que tu utlises ce jar du genre, CLASSPATH=%CLASSPATH%;$catalina_home\common\lib\ tonjar.jar

n°1559030
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 16:39:41  profilanswer
 

Pour le moment, dans le path il y a
$catalina_home\common\lib\
$catalina_home\shared\lib\  
 
Et j'ai mis mon jar et ma dll dans shared\lib

n°1559036
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 16:47:02  profilanswer
 

C'est bon j'ai trouvé.
 
Il faut mettre sa lib (.dll) et et le fichier qui la charge (.jar) dans $catalina_home\common\lib\

n°1559039
yaltar
Posté le 11-05-2007 à 16:48:15  profilanswer
 

Ha tant mieux alors :)
 
Content pour toi.
 
Pense à mettre : Résolu, si c'est bon :)

n°1559064
negatifman
oh oh Yeahhhhhhhhhhhhhhhhhhh
Posté le 11-05-2007 à 17:12:36  profilanswer
 

Ok, pas de soucis :)


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

  Webservices et JNI [resolu]

 

Sujets relatifs
[Resolu]executer script sur machine distante[Résolu] Conflit entre deux fichiers js (plusieurs onLoad)
[RESOLU] ASP.NET et AJAX 1.0, intellisense KORésolu : Je cherche l'outil de saisie style explorateur en VB
[Résolu][Débutant C#] - Requete SQLCalcul de durée totale/de session
Calcul de nombres complexes [RESOLU][Résolu] Comment faire ???
[résolu] [DOS] del sans confirmation[résolu] lien entre la 3D et c#
Plus de sujets relatifs à : Webservices et JNI [resolu]


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