Solved

Servlets and JNI

Posted on 2001-06-08
9
527 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

708 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

17 Experts available now in Live!

Get 1:1 Help Now