This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Services and the fly likes include native library with webservice deployement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "include native library with webservice deployement" Watch "include native library with webservice deployement" New topic
Author

include native library with webservice deployement

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hi,
I wrote a webservice which i'm deploying to tomcat server. the methods of this webservice require a native library (.so) to work correctly.
I'm not sure where can i put this .so library so my deployed java webservice will find it when running in tomcat server?

also In netbeans IDE version 6.7 the IDE doesn't find any native library and i can't figure out how to tell netbeans where to find these native libraries.

any help where i should put the .so file within my webservice deployement ?

thanks.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hi,
i did some workarounds with Tomcat to add the java.library.path env variable pointing to my native libs folder.
now the native library is loaded by tomcat server at startup..but i get another tomcat error :




what this error means and how to fix it?

thanks much.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42360
    
  64
Native libraries can only get loaded by a single classloader at any one time. For web apps that means that only a single web app can load the library; it also means that there may be problems if a web app -which uses a native library- gets reloaded.


Ping & DNS - my free Android networking tools app
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Ulf Dittmer wrote:Native libraries can only get loaded by a single classloader at any one time. For web apps that means that only a single web app can load the library; it also means that there may be problems if a web app -which uses a native library- gets reloaded.


Thanks for the reply.
So what is the best solution for loading native libraries by java web apps? is there a technique to control the one time loading of the native libraries so that even if the web app is reloaded the native libs doesn't get loaded many times?

I have another jar library that loads this native library. i include this jar in my web apps libs together with the native library. so i don't have control over the code loading the native lib. what can one do in this situation?

thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42360
    
  64
One way would be to load the library from code that's guaranteed to be loaded only once. If the pertinent code was part of a jar file in TOMCAT_HOME/common/lib that would be the case. As long as it's loaded by any of the web app classloaders there'll be problems.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Ulf Dittmer wrote:One way would be to load the library from code that's guaranteed to be loaded only once. If the pertinent code was part of a jar file in TOMCAT_HOME/common/lib that would be the case. As long as it's loaded by any of the web app classloaders there'll be problems.

You mean if i place my native library in TOMCAT_HOME/common/lib directory , the Previous error will disappear ? if this is the case this means the cleanest solution to use native libraries in java web apps is to place them in the web container 'lib' folder..or am i wrong?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42360
    
  64
You mean if i place my native library in TOMCAT_HOME/common/lib directory , the Previous error will disappear ?

No. Native libraries need to be in the PATH, not in the CLASSPATH. It doesn't matter much *where* in the PATH it is, though. The Java code that *loads* the native library needs to be in a place where it's loaded by a single classloader only, and common/lib fulfills that requirement.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: include native library with webservice deployement