Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

Using JNI in a Servlet

Thread view: 
steves-un@comcast.net - 30 May 2005 19:32 GMT
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.
Gordon Beaton - 31 May 2005 08:30 GMT
> 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:
>
[quoted text clipped - 14 lines]
>     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

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Alan Krueger - 01 Jun 2005 05:05 GMT
> 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
[quoted text clipped - 3 lines]
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.