participate


Java Native Interface (JNI) - JNI Dll - java.library.path
<<   Back to Forum  |   Give us Feedback
This topic has 12 replies on 1 page.
E10
Posts:30
Registered: 10/25/06
JNI Dll - java.library.path   
Oct 25, 2006 12:37 PM

 
I developed and application which uses a dll to get data from windows registry, there is a dll located at a directory included in PATH environment variable. Ir works fine If I invoke it from and standalone application, but When I tested it from a Web App hosted in Tomcat, It throws a javalinkunsatisfiedException. It seems like TomCat gets a different value for PATH Variable.

- Where does TomCat get java.library.path value?
- How Can I include a new directory there, if I want to place the dll at C:\Program Files\Tomcat 5.0\comon\shared?

Thanks in advance.
 
jfbriere
Posts:2,433
Registered: 8/11/03
Re: JNI Dll - java.library.path   
Oct 25, 2006 3:02 PM (reply 1 of 12)  (In reply to original post )

 
You must place the jar file that has the JNI Java classes in the {CATALINA_HOME}\shared\lib folder.
If the folder doesn't exist then create it.
The JNI DLL must be located somewhere visible from either the java.library.path java system property or the Path windows system (or user) property.
To set the java.library.path java system property with Tomcat simply set the JAVA_OPTS environment variable before executing {CATALINA_HOME}\bin\startup.bat:
set CATALINA_HOME=someTomcatRootFolder
set JAVA_HOME=someJavaRootFolder
set JAVA_OPTS=-Djava.library.path=someJniDllPath
cd "%CATALINA_HOME%\bin"
call startup.bat
 
E10
Posts:30
Registered: 10/25/06
Re: JNI Dll - java.library.path   
Oct 26, 2006 1:31 PM (reply 2 of 12)  (In reply to #1 )

 
What file do u mean when u say: "jar file that has the JNI Java classes".?
Is that a specific .jar file? What is its name?

Thank u
 
jfbriere
Posts:2,433
Registered: 8/11/03
Re: JNI Dll - java.library.path   
Oct 26, 2006 2:46 PM (reply 3 of 12)  (In reply to #2 )

 
I mean your custom made Java class(es) that use JNI calls (System.loadLibrary() and native methods).
You cannot place it(them) under your web application WEB-INF/lib or WEB-INF/classes folder because of multiple class loading problem with JNI in the same JVM.
You have to place it(them) under a common Tomcat folder.
It could be either under {CATALINA_HOME}\shared\lib as a custom made jar file or under {CATALINA_HOME}\shared\classes as your compiled .class files.

Regards
 
E10
Posts:30
Registered: 10/25/06
Re: JNI Dll - java.library.path   
Oct 27, 2006 7:21 AM (reply 4 of 12)  (In reply to #3 )

 
Hi achieved to establish the java.library.path to the desired path: CATALINA_HOME/shared/classes, although I am getting the following error:

java.lang.UnsatisfiedLinkError: Native Library C:\Program Files\Apache Software Foundation\Tomcat 5.0\shared\classes\jRegistryKey.dll already loaded in another classloader

This ocurrs because There are 2 applications hosted at my Tomcat Server, is there any way to solve this issue?

Thanks for ur help!
Esteban
 
jfbriere
Posts:2,433
Registered: 8/11/03
Re: JNI Dll - java.library.path   
Oct 30, 2006 2:01 PM (reply 5 of 12)  (In reply to #4 )

 
This ocurrs because There are 2 applications hosted at my Tomcat

This means that one (or both) your web application(s) is (are) using Java JNI classes that load the same native library and that those Java classes are NOT located under the Tomcat shared folder.
There must be NO Java JNI classes under any WEB-INF/classes or WEB-INF/lib folder.
 
prafullk
Posts:6
Registered: 8/29/00
Re: JNI Dll - java.library.path   
Jul 14, 2007 9:05 AM (reply 6 of 12)  (In reply to #4 )

 
Hi E10,

I am also facing the same problem with my web application. I am getting the same exception.

Can you please share how you overcame this problem?

Thanks
Prafull
 
dkho
Posts:1
Registered: 9/2/07
Re: JNI Dll - java.library.path   
Sep 2, 2007 3:22 AM (reply 7 of 12)  (In reply to #6 )

 
hi jfbriere, i'm facing this problem too.
Thanks a lot for your help. This worked. ;)
 
muellermi
Posts:1
Registered: 4/16/08
Re: JNI Dll - java.library.path   
Apr 16, 2008 8:18 AM (reply 8 of 12)  (In reply to #7 )

 
Hi,

Since I faced same problem (unsatisfiedLinkError), I followed the suggestions in this thread.
I created a lib containing a call to C dll. Works fine in stand alone app. Idropped this to [CATALINA_HOME]\shared\lib.
Netbeans recognised this lib and I'm able to build my web app.
Deploying my web app I'll get a class not found error, caused by the line caling my lib.:(
Any idea?

Michael
 
jschell
Posts:36,985
Registered: 11/3/97
Re: JNI Dll - java.library.path   
Apr 16, 2008 12:05 PM (reply 9 of 12)  (In reply to #8 )

 
Deploying my web app I'll get a class not found error, caused by the line caling my lib.:(

Only way that would happen is if you are using a static initializer and not catching the exception when the library load fails.

As noted the system properties will tell you exactly what paths are available in the application by looking at the java.library.path in there when an app is running.
 
praveekan
Posts:15
Registered: 5/27/08
Re: JNI Dll - java.library.path   
May 29, 2008 1:32 AM (reply 10 of 12)  (In reply to #8 )

 
u want to place the dll in ur bin. else
say for an eg., u have x.dll
and you have your class in the project called y
y-> u have ur bin, src u have to place ur dll into the bin.

if u r using any web application, u have to place the dll into server bin
 
jschell
Posts:36,985
Registered: 11/3/97
Re: JNI Dll - java.library.path   
May 29, 2008 11:14 AM (reply 11 of 12)  (In reply to #10 )

 
praveekan wrote:
u want to place the dll in ur bin. else
say for an eg., u have x.dll
and you have your class in the project called y
y-> u have ur bin, src u have to place ur dll into the bin.

if u r using any web application, u have to place the dll into server bin

Basically wrong.
 
KAditi
Posts:1
Registered: 7/15/08
Re: JNI Dll - java.library.path   
Jul 14, 2008 11:27 PM (reply 12 of 12)  (In reply to #11 )

 
Hello jschell,

I encountered the same problem while developing a Web App which calls a dll.
It throws ClassNotFound exception.
I have ensured that the dll is at a location which is listed under java.library.path.
Also, the classes which load the library are placed in Tomcat 5.0\shared\classes folder.
Thanks
 
This topic has 12 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 22
  • Guests : 132

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums