Tomcat can't work well with Java Class that loads two shared libraries?
Dear All,
here is my environment:
Fedora Core 6/Tomcat 5.5.23/JRE 1.5.0_11_b03.
My Goal is to develop a web service to connect to a legacy DB with a C library.
There is a shared library a.so that contains C APIs to connect to that legacy DB.
so I decide to use JNI to access this DB through its shared library a.so. here is what I did:
1. create an C file that contains functions that will call the APIs in a.so to access the DB. Of course, these C functions will implement the .h header files generated by javah.
2. since these functions use the APIs in a.so, so I compile this C file(AMSLibCalls.c) with
a. gcc -fPIC -c -I/opt/jdk1.5.0_11/include -I/opt/jdk1.5.0_11/include/linux -Wall AMSLibCalls.c
b. gcc -shared -I/opt/jdk1.5.0_11/include -I/opt/jdk1.5.0_11/include/linux -Wl,-soname,libAMSLibCalls.so.1 -o libAMSLibCalls.so AMSLibCalls.o ./a.so -lc
to generate another shared library libAMSLibCalls.so.
3. since shared lib libAMSLibCalls.so will call the shared lib a.so, so in the Java class AMSJavaAPI.java, I load both of these two shared libs:
static{
System.load("/usr/src/ams/a.so");
System.load("/usr/src/ams/libAMSLibCalls.so");
}
4. everything works fine if I don't put this AMSJavaAPI class in Tomcat.
5. if I put this class in tomcat and use a jsp page to call it, it will always give me the NoClassDefFound exception. I looked at the exception, it seems when the lib libAMSLibCalls.so is loaded, it searchs the a.so too and can't find it.
does anybody have clue what possibly goes wrong?
Thanks,
Alex Hu
[1657 byte] By [
AlexHua] at [2007-11-27 4:08:03]

# 1
> 4. everything works fine if I don't put this
> AMSJavaAPI class in Tomcat.
>
You mean that it loads both libraries if it isn't in Tomcat?
If yes, then it is one of the following.
1. The paths are not correct.
2. It is permissions problem
3. There is another dependency by a.so which can't be loaded due to it is not found or permissions.
Note that often printing the stack trace can give more information.
# 4
Thank you for the explanation! jschell,
I did chmod all related files to 777 and do the test again, it turns out no go. here is the stack trace:
INFO: Server startup in 4481 ms
- Servlet.service() for servlet AxisServlet threw exception
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at org.apache.axis.utils.ClassUtils$2.run(ClassUtils.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.axis.utils.ClassUtils.loadClass(ClassUtils.java:160)
at org.apache.axis.utils.ClassUtils.forName(ClassUtils.java:142)
at org.apache.axis.utils.cache.ClassCache.lookup(ClassCache.java:85)
at org.apache.axis.providers.java.JavaProvider.getServiceClass(JavaProvider.java:428)
at org.apache.axis.providers.java.JavaProvider.initServiceDesc(JavaProvider.java:461)
at org.apache.axis.handlers.soap.SOAPService.getInitializedServiceDesc(SOAPService.java:286)
at org.apache.axis.deployment.wsdd.WSDDService.makeNewInstance(WSDDService.java:500)
at org.apache.axis.deployment.wsdd.WSDDDeployment.getDeployedServices(WSDDDeployment.java:503)
at org.apache.axis.configuration.FileProvider.getDeployedServices(FileProvider.java:296)
at org.apache.axis.transport.http.AxisServlet.reportAvailableServices(AxisServlet.java:482)
at org.apache.axis.transport.http.AxisServlet.doGet(AxisServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)
BTW, I logged in as root, so all the classes' owners are root. I put AMSJavaAPI class as a web service class using Axis Soap engine. this is why your see the axis in the stack trace.
Gosh, really have no clue what happened.
-AH