JNI Works for application, but not when used over Tomcat...

I am having problems getting JNI to work when I try to run a Servlet that invokes native calls.

I have a small, simple java program, just to test the waters, that simple calls a small shared library. It works like magic when I run the program as a simple application.

However, when I turn it into a Servlet, I get the following runtime errors:

The first time I call the Servlet:

__

java.lang.ExceptionInInitializerError: java.security.AccessControlException: access denied (java.lang.RuntimePermission loadLibrary.native)

at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)

at java.security.AccessController.checkPermission(AccessController.java:399)

at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)

at java.lang.SecurityManager.checkLink(SecurityManager.java:837)

at java.lang.Runtime.loadLibrary0(Runtime.java:743)

at java.lang.System.loadLibrary(System.java:820)

at Native.(NativeApp.java:24)

at NativeApp.service(NativeApp.java:15)

at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)

at org.apache.tomcat.core.Handler.service(Handler.java:286)

at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)

at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)

at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)

at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)

at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)

at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)

at java.lang.Thread.run(Thread.java:484)

On hitting reload (F5), I get this:

java.lang.NoClassDefFoundError

at NativeApp.service(NativeApp.java:15)

at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)

at org.apache.tomcat.core.Handler.service(Handler.java:286)

at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)

at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)

at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)

at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)

at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)

at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)

at java.lang.Thread.run(Thread.java:484)

Before going and farther, here is the server specs:

Linux (cobalt, basically red hat)

java 1.3

recent version of tomcat

Now, just to be sure, I removed the native call from the servlet, and ran it again...no problem this time. So I know that it has to be the native call that is causing this.

I have to say that I am still a bit new to JNI (book is in the mail form amazon still, hehe)...any ideas would really be appreciated.

I have a feeling that this may have little or nothing to do with JNI...but it seems to be related in some way.

-Zach

[3278 byte] By [JavaZach] at [2007-9-26 9:31:15]
# 1
It is a security exception so you might want to look at the policy file.
jschell at 2007-7-1 20:56:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Well, I have came to the same conclusion, that the problem that I am having is directly related to the security policy that Tomcat runs under.

However, I have not been able to figure out exactly what I need to change....

I have altered the tomcat.policy file in a number of ways, including (for testing purposes) allowing full permission on the site that has the JNI servlet on it.

I have also done the same for the folder containing the shared library, I don't know if mattered, but I tried to be sure.

At this point, I have ordered a number of books from Amazon that should (hopefully) have some answers, but it is still a bit confusing that after allowing all permissions (and rebooting) that it still failed to work.

Dose anyone know how that you would allow native methods to be called in a policy file?

Thanks again for any suggestions!

-Zach

JavaZach at 2007-7-1 20:56:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...