Solved

Servlets and JNI

Posted on 2001-06-08
9
528 Views
Last Modified: 2013-11-24
I am having a lot of trouble invoking functions in a Windows DLL using JNI from within a servlet.  I can load the same DLL and execute functions in it with no problem using the normal java runtime but as soon as I try to do it using a servlet under Tomcat 3.2 I get the following error:

     java.lang.UnsatisfiedLinkError: Init0

The servlet I'm attempting to use is located in the WEB-INF\classes directory as is the windows DLL.  Does anyone have any idea why this would not work?
0
Comment
Question by:derekl
  • 4
  • 3
  • 2
9 Comments
 

Expert Comment

by:smileyxx
ID: 6168962
Look at your java.library.path System property. It needs to have the directory containing your shared library.

There is a quick & easy way to do this. Copy the shared library into your jre's client library directory.

For instance on solaris, this would be:
$JAVA_HOME/jre/lib/sparc/client,

on Linux:
$JAVA_HOME/jre/lib/i386/client.

This is a relatively painless way to do it. You may try setting LD_LIBRARY_PATH to the directory containing the shared library, but often the server will set it's own LD_LIBRARY_PATH.
0
 

Author Comment

by:derekl
ID: 6168972
OK, I've got a stupid question.  What are java.library.path and LD_LIBRARY_PATH are they both environment varialbes?
0
 

Expert Comment

by:smileyxx
ID: 6169008
LD_LIBRARY_PATH is a user environment variable, java.library.path is a System property of the JVM.
(e.g.
System.out.println(System.getProperty("java.library.path"));
0
 

Author Comment

by:derekl
ID: 6169043
So I would have to set java.library.path to include the directory containing my dll at runtime in order to ensure everything works as planned?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Accepted Solution

by:
sghosh092199 earned 200 total points
ID: 6169049
LD_LIBRARY_PATH is an environment variable in UNIX Environment. The same is PATH in Windows. Its value can be returned to Java application by the following call:

String libPath = System.getProperty("java.library.path");
 
If your shared library is libname.so or libname.DLL, make sure that the path contains an entry like /usr/dir1/dir2/libname.so or /usr/dir1/dir2/libname.DLL


0
 

Author Comment

by:derekl
ID: 6169115
OK, I've got a new problem.  Although I can load the library correctly now, as soon as I try to execute a native method I get the following error:

    java.lang.UnsatisfiedLinkError: displayHelloWorld

0
 

Author Comment

by:derekl
ID: 6169128
Sorry smileyxx I meant to give the answer to you and I just clicked on the wrong comment by mistake.  Is there any way I can give you the 200 points?
0
 

Expert Comment

by:smileyxx
ID: 6169286
Don't worry about the pts.
Make sure the function you're calling is in the loaded version of the DLL. Due to a bug in the JVM, it may require a restart of the server.
0
 
LVL 3

Expert Comment

by:sghosh092199
ID: 6169361
It was too quick an evaluation though.

Say, your method signature in file RemoteServer.java is as follows:
 public native void displayHelloWorld();

'javah RemoteServer' will generate RemoteServer.h which needs to be included in DLL.

Make sure in that case the DLL implements a function as follows:
JNIEXPORT void JNICALL
Java_RemoteServer_displayHelloWorld(JNIEnv *env, jobject obj)

In case more parameters have been passed, they need to have the correct mapping. Say, int should be represented as jint.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 25
how to add new optional parameter to JSP 1 29
Oracle SQL syntax check  without executing 6 36
servlet example issue 6 31
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now