• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

include native library with webservice deployement

 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic