AW: Native library cannot be loaded twice
Hi, Andreas. A bit off-topic (this goes into native programming), but there is something whirling through my head: Static classes/members are instantiated once. But what happens if multiple classloaders are used? Such as you have this one class static but use it in several web applications? Seems like it MUST reside in common/lib instead of webapp/*/web-inf/lib? Hiran -Ursprüngliche Nachricht- Von: Andreas Hirner [mailto:[EMAIL PROTECTED]] Gesendet: Dienstag, 25. Juni 2002 13:14 An: Tomcat Users List; [EMAIL PROTECTED] Betreff: Re: Native library cannot be loaded twice Hallo Franz, Concerning the JDK documentation a native lib should be loaded in a static scope. Static resources are processed differently, because the runtime systems has to initialize all static resources at the beginning. After that the runtime system tries to initialize objects and these objects can - of course - use all static resources. A look into your code (InitMapserver) shows, that the runtime system cannot initialize the static resource in the common way, because it first must generate an object and this object contains code for doing some static stuff. Maybe this is the reason for the strange behavior. I am sorry, but I am not a skilled Java Programmer and I don't quite understand what you mean. Can you try to explain it more explicitly or give some examples. I hope I am not asking to much Thanks Andreas -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
AW: Native library cannot be loaded twice
Depends on which classloader finds the class. If you have a classloader hierarchy as tomcat, you can have either one instance of the class (the class is only found through the parent class loader) or several instances of the class (some or all context class loader find the class on their own and have their own instance) http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html -Ursprüngliche Nachricht- Von: Software AG [mailto:[EMAIL PROTECTED]] Gesendet: Dienstag, 25. Juni 2002 13:14 An: 'Tomcat Users List' Betreff: AW: Native library cannot be loaded twice Static classes/members are instantiated once. But what happens if multiple classloaders are used? Such as you have this one class static but use it in several web applications? -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
AW: Native library cannot be loaded twice
Hi, What kind of native library are you loading ? (Sorry, I don't know the former emails!) If you working on Unix and you are loading a shared lib you must ensure that the path to the lib is know to the tomcat process. Either you configure the tomcate environment (catalina) or use the LD_LIBRARY_PATH environment variable. Manipulating an environment variable is not the best idea because it effects the whole system - and this is neither allowed nor requested. This should also work for Windows where the path to the dll must be provided either in the catalina.bat file or by modifying the system wide path. franzR -Ursprüngliche Nachricht- Von: Andreas Hirner [mailto:[EMAIL PROTECTED]] Gesendet: Montag, 24. Juni 2002 12:33 An: Tomcat Users List Cc: [EMAIL PROTECTED] Betreff: SV: Native library cannot be loaded twice Hi, Usatisfied link error means that it is not finding it or something it relies on. Hermod Ok. But in order to make sure I loaded the native library successfully, would you agree with me that I took the right steps? I am not that familiar with tomcat and appreciate any hint. Andreas -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
AW: Native library cannot be loaded twice
Concerning the JDK documentation a native lib should be loaded in a static scope. Static resources are processed differently, because the runtime systems has to initialize all static resources at the beginning. After that the runtime system tries to initialize objects and these objects can - of course - use all static resources. A look into your code (InitMapserver) shows, that the runtime system cannot initialize the static resource in the common way, because it first must generate an object and this object contains code for doing some static stuff. Maybe this is the reason for the strange behavior. franzR -Ursprüngliche Nachricht- Von: Andreas Hirner [mailto:[EMAIL PROTECTED]] Gesendet: Montag, 24. Juni 2002 13:43 An: Tomcat Users List Cc: [EMAIL PROTECTED] Betreff: Re: Native library cannot be loaded twice Hi Yes. But have you ensured that your native library and its dependends are in the java.library.path ? Hermod Tomcat runs on linux and the path of the native library is set via the LD_LIBRARY_PATH variable. If I load the native library in the servlet, the library is accessed correctly and does what it is supposed to do. However, when I initialise the library in the InitMapserver class and call it in the servlet via the class.forName method (see below) the servlet does not work properly. Andreas ok, I realised that I cannot load a native library twice. So I wrote and compiled a class called InitMapserver, which looks like that: public class InitMapserver { static { try { System.loadLibrary(mapscript); System.err.println(libmapscript.so loaded); } catch (UnsatisfiedLinkError e) { System.err.println(libmapscript.so not loaded: + e); } } } and put it into the common/classes directory. Then I try to load this class in a servlet doing: public void init(ServletConfig config) throws ServletException { try { Class.forName(InitMapserver); } catch (ClassNotFoundException ex) { file://throw new ServletException(ex.getMessage() + Class InitMapserver not found); System.err.println(ex.getMessage() + Class InitMapserver not found); } } -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
AW: Native library cannot be loaded twice
Hi, What kind of native library are you loading ? (Sorry, I don't know the former emails!) I am working on Linux and set the path to the shared C library using the LD_LIBRARY_PATH. If you working on Unix and you are loading a shared lib you must ensure that the path to the lib is know to the tomcat process. Either you configure the tomcate environment (catalina) or use the LD_LIBRARY_PATH environment variable. Manipulating an environment variable is not the best idea because it effects the whole system - and this is neither allowed nor requested. This should also work for Windows where the path to the dll must be provided either in the catalina.bat file or by modifying the system wide path. The problem is, that I can load the library in the servlet and make it work. However if I change the servlet and reload the application via manager/reload command, the library is loaded a second time and thus causes a conflict. I have to start the application to view any changes, which is rather cumbersome if you are still developing. That's why I wrote the InitMapserver class and called it from the servlet in the Class.forName() method. Looking at your second mail: A look into your code (InitMapserver) shows, that the runtime system cannot initialize the static resource in the common way, because it first must generate an object and this object contains code for doing some static stuff. Maybe this is the reason for the strange behavior How do I go about this. Do I have use a constructor? Thanx Andreas -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]