Native Library placing in JDK
Hi, In one of our applications we have a native library kdmjj.dll, that is contained in the bin directory of the app. This works fine and gets picked up if the customer copies the dll to $JAVA_HOME\jre\bin. This I take it is the default place to put native libraries so they get picked up by the JVM? I would like to be able to pick the native library up straight from inside the application in the bin directory and not have to copy it to inside the JDK. I have tried adding the dll to the PATH and CLASSPATH environment variables but this doesnt work. I have heard there is some environment variable which will tell where to look for native libraries, do you know what this is?
Thanks in advance,
John
[724 byte] By [
damonha] at [2007-10-3 7:36:34]

You should be able to put any directory you want in the PATH environment variable, and the jvm should find the DLL.
Hey,
cheers for the reply. What your saying is what I have been told by everyone else, but it doesnt seem t work that way. If I have the dll in %JAVAHOME%\bin\jre and %MY_APPLICATION\bin% it works fine. But these locations are in my PATH. But if I take the DLL out of %JAVAHOME%\bin\jre the application no longer works.
John
One thing you could do is try this with another - not java - program. Find some harmless .exe file, and try moving it around. The one we are after is
o some j-random location.
o that has been defined into your classpath.
See if you can then go to a dos box in yet another location, and successfully start the .exe just typing the program name.
if this doesn't work, then I'm not sure whhat's up.
Simple example:
I have a directory c:\util. It contains utilities that I may use from just about any other directory - say grep, or something like that. This directory is most definitely in my PATH environment variable (set through
o right click on my computer icon.
o select Properties
o select Advanced tab
o push Environment Variables button.
o edit "Path" in the system-wide variables.)
> Hey,
>
> cheers for the reply. What your saying is what I have
> been told by everyone else, but it doesnt seem t work
> that way. If I have the dll in %JAVAHOME%\bin\jre and
> %MY_APPLICATION\bin% it works fine. But these
> locations are in my PATH. But if I take the DLL out
> of %JAVAHOME%\bin\jre the application no longer
> works.
It must be located in one of the directories in the String returned by a call to
System.getProperty("java.library.path");
It should be in the java library path. If you are using eclipse 3.2, the Native libarary location can be added here:Project->properties->Java Build Path->Libraraies->JRE System Libraries->Native Library location.
Hey,tried all of the above and nothing seems to work. Cheers for the replies, my path is correct and the bin directory is definitely in the java.library.path. The problem must lie somewhere else.Cheers,John
> Hey,
>
> tried all of the above and nothing seems to work.
> Cheers for the replies, my path is correct and the
> bin directory is definitely in the java.library.path.
> The problem must lie somewhere else.
>
To be quite clear....
In windows the OS, not java, locates dlls via the env path var (if an explicit path is not provided.) Java uses the OS to load the dll.
So unless you are using an explicit path this has nothing to do with java itself.
If the dll is not being found in java via that path then one of the following is wrong.
1. The path to the dll is not in your env path variable.
2. There is something wrong with your env path variable. It is malformed.
3. You are using a server application (like jboss) which modifies the env path variable in its start up script. Consequently changing the system env path variable is not going to have any impact on the server application.