Using JNI in a Servlet

Discussion in 'Java' started by steves-un@comcast.net, May 30, 2005.

  1. Guest

    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.
     
    , May 30, 2005
    #1
    1. Advertising

  2. On 30 May 2005 11:32:25 -0700, wrote:
    > 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

    --
    [ 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
     
    Gordon Beaton, May 31, 2005
    #2
    1. Advertising

  3. Alan Krueger Guest

    wrote:
    > 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.
     
    Alan Krueger, Jun 1, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley

    IBM's JNI fails where Sun's JNI works

    Alex Hunsley, Nov 3, 2003, in forum: Java
    Replies:
    4
    Views:
    882
    Alex Hunsley
    Nov 4, 2003
  2. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Replies:
    5
    Views:
    943
    Pasturel Jean-Louis
    Mar 3, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    2,081
    Jack Jia
    Apr 4, 2004
  4. vasanth
    Replies:
    0
    Views:
    2,780
    vasanth
    Jan 25, 2005
  5. vasanth
    Replies:
    0
    Views:
    640
    vasanth
    Jan 25, 2005
Loading...

Share This Page