JNI Dll - java.library.path

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.

[585 byte] By [E10a] at [2007-10-3 8:15:09]
# 1

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

jfbrierea at 2007-7-15 3:20:08 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
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
E10a at 2007-7-15 3:20:08 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

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

jfbrierea at 2007-7-15 3:20:08 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

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

E10a at 2007-7-15 3:20:08 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

> 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.

jfbrierea at 2007-7-15 3:20:08 > top of Java-index,Java HotSpot Virtual Machine,Specifications...