tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hermod.opstv...@dnb.no
Subject SV: Native library cannot be loaded twice
Date Tue, 25 Jun 2002 11:44:32 GMT
Hi  Andreas

Again, as I said earlier - Have you checked that the java.library.path
has is pointing to where your native library is. The reason you are
seeing this, is that when loading through common/classes it is the
system classloader (different from the application classloader) that
loads it. Try altering the startupfile for catalina adding :
-Djava.library.path=......


Hermod

-----Opprinnelig melding-----
Fra: Andreas Hirner [mailto:andreas@projektinter.net]
Sendt: 25. juni 2002 13:41
Til: Tomcat Users List
Kopi: sag@stark-verlag.de
Emne: Re: Native library cannot be loaded twice


Hi,

> 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

This is where my problem is. I was developing a servlet, which loaded
a native library and subsequently called some native functions.
Everything was working fine, but whenever I made changes to the
servlet and reloaded the application with the manager/relaod call the
native library was instanciated a second time and crashed. I had to
stop and restart tomcat in order to see any changes made to the
servlet.

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");
  }
 }

Unfortunately this does not work. Any suggestions???

Thanks
Andreas

> > > 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....




--
To unsubscribe, e-mail:
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

This email with attachments is solely for the use of the individual or
entity to whom it is addressed. Please also be aware that DnB cannot
accept any payment orders or other legally binding correspondence with
customers as a part of an email. 

This email message has been virus checked by the virus programs used
in the DnB Group.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message