Using JNI in a Servlet

S

steves-un

Does anyone have experience with using JNI in a servlet under Windows
XP? When trying to do this, it continually fails to load the C
library.
It works when done in a normal Java program, but not when it's a
servlet.
I've seen that others have used JNI in Servlets and had this problem
with Windows, but no explanation on how to work around the problem.

I also have problems running javah. It's not required, but it does
work
as a precursor; if javah doesn't work, the library won't load either.

Here's a quick rundown of the setup and errors. I'ms using Java 1.5
with the Sun App Server on a Windows XP SP2 system, compiling the C
code
with gcc v3.3.3. CLASSPATH is set to inculde all directories the files
and libs reside.

When running the servlet, the following errors show up in the App
Server
log file:

Logger: javax.enterprise.system.stream.err
Name-Value Pairs: _ThreadID=29;
Message ID: Link error
Complete Message java.lang.UnsatisfiedLinkError: no jni_if in
java.library.path

Logger: javax.enterprise.system.stream.err
Name-Value Pairs: _ThreadID=12;
Message ID:
Complete Message Exception in thread "Thread-79"

Logger: javax.enterprise.system.stream.err
Name-Value Pairs: _ThreadID=30;
Message ID: java.lang.UnsatisfiedLinkError
Complete Message getXppParm
at xpserv.XppIf.getXppParm(Native Method)
at xpserv.XppIf.run(XppIf.java:61)


Running javah gets the following error:

bash-2.05b$ javah -jni XppIf
error: cannot access XppIf
bad class file: C:\BioSpring\xpserv\XppIf.class
class file contains wrong class: xpserv.XppIf
Please remove or make sure it appears in the correct subdirectory
of the classpath.
com.sun.tools.javac.util.Abort
:

Running javah with the package name included in the name still fails:

bash-2.05b$ javah -jni xpserv.XppIf
error: cannot access xpserv.XppIf
file xpserv\XppIf.class not found
javadoc: error - Class xpserv.XppIf not found.
Error: No classes were specified on the command line. Try -help.

If anybody has had any success in using JNI with a servlet, I would to
hear how they configured it to work.
 
G

Gordon Beaton

If anybody has had any success in using JNI with a servlet, I would
to hear how they configured it to work.

The first step is to get javah working properly (and this has nothing
to do with servlets)...
Running javah gets the following error:

bash-2.05b$ javah -jni XppIf
error: cannot access XppIf
bad class file: C:\BioSpring\xpserv\XppIf.class
class file contains wrong class: xpserv.XppIf
Please remove or make sure it appears in the correct subdirectory
of the classpath.
com.sun.tools.javac.util.Abort
:

Running javah with the package name included in the name still fails:

bash-2.05b$ javah -jni xpserv.XppIf
error: cannot access xpserv.XppIf
file xpserv\XppIf.class not found
javadoc: error - Class xpserv.XppIf not found.
Error: No classes were specified on the command line. Try -help.

You *must* use the package name when you run javah, or the generated
symbol names will be incorrect and you will get UnsatisfiedLinkErrors
when you try to invoke them.

The second example fails because you need C:\BioSpring in the
classpath, not C:\BioSpring\xpserv.

/gordon
 
A

Alan Krueger

Does anyone have experience with using JNI in a servlet under Windows
XP? When trying to do this, it continually fails to load the C
library.
It works when done in a normal Java program, but not when it's a
servlet.
I've seen that others have used JNI in Servlets and had this problem
with Windows, but no explanation on how to work around the problem.

A JNI library can only be loaded once per JVM instance under Windows.
Subsequent attempts will result in an UnsatisfiedLinkError, IIRC.
You'll need to ensure it only ever gets loaded once.

Under Tomcat, IIRC, place the enclosing jar file in common/lib or the
class file in common/classes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top