Add .dll to java.library.path in Eclipse/PyDev Jython project
Asked Answered
Q

3

23

I'm trying to use a compiled .jar Java library in my PyDev Jython project.

I successfully added the .jar to the PYTHONPATH and was able to begin coding with auto complete working.

The library requires a .dll extension as well, javaHeclib.dll, so I added that to the External Libs section of my project.

I can import the library fine, but I get an error when I try to access any of its functions:

java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: no javaHeclib in java.library.path

I added a VM argument to my Run Configuration, with no luck:

-Djava.library.path="Y:/path/to/javaHeclib.dll;${env_var:PATH}"

I can run the library from the command line just fine using the java.library.path above.

Experimenting in the PyDev Console, I noticed I can load the .dll extension with an absolute path, but not a relative one:

>>> import java.lang
>>> java.lang.System.load('Y:/path/to/javaHeclib.dll')
>>> java.lang.System.loadLibrary('javaHeclib')
Traceback (most recent call last):
  File "<console>", line 1, in ?
java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: no javaHeclib in java.library.path

Unfortunately, the library is using the the System.loadLibrary call above, and I don't have access to its source.

Why is javaHeclib.dll not in my java.library.path?

EDIT

Setting the java.library.path to the directory containing the dll didn't allow me to load it using System.loadLibrary.

-Djava.library.path="Y:/path/to/dll/;${env_var:PATH}"

(Using forward slashes didn't make a difference.) I also tried changing the default VM args in eclipse.ini, with no luck:

-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx384m
-Djava.library.path="Y:\path\to\dll\;${env_var:PATH}"
Quintuplicate answered 20/6, 2012 at 15:47 Comment(3)
I think you should set java.library.path to include the directory that contains the DLL file.Bravery
Thanks for the help. Unfortunately, that didn't seem to make a difference. Original question updated.Quintuplicate
You were right, I needed to set java.library.path to include the directory rather than the actual file. See my answer.Quintuplicate
Q
11

I got this working.

For future reference:

Say the dll you need is in Y:\path\to\dlls\lib\. Then set your Run Configuration's working directory to Y:\path\to\dlls\ and set your VM arguments to include -Djava.library.path=lib.

That's it, it should now work. I don't know why specifying an absolute path in java.library.path didn't work previously, but setting a working directory seems to have done it.

Perhaps it's something peculiar to the specific library I'm using (or that Eclipse is running from a different drive than the library is on)...

Quintuplicate answered 20/6, 2012 at 22:13 Comment(1)
Well this worked for me while development. And if I'm using a .bat-file to run my program it works if the .dll files are in the same directory as the .jar file is. java -jar sample.jar But if I just want to start the .jar file without a .bat it seems it can't find the .dll files. Do I need to put them in a special folder to get my .jar file find them? I tried every folder-solution my mind came up with but nothing worked.Venezuela
P
56

I think the better way is:

  1. Create a folder under the project, for example dll.
  2. Copy/paste all dll files into this folder.
  3. In project -> Properties -> Java Build Path -> Source, click and expand the source details.
  4. You will see Native library location, click/highlight it.
  5. Then click edit on the right, click workspace again. You can see the dll folder under the project.
  6. Select it and click OK, OK. You will see the dll is added in the Native library location.

That's it. You do not need to manually change anything in configuration.

Java Build Path configuration

Phoebe answered 1/2, 2013 at 18:35 Comment(4)
Amazing. That is better that the manual edits. Thanks a lot !Maclean
@Phoebe I followed your way but it throws the exception: Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\Users\four.four-PC\eclipse-workspace\BiometricAuthentication\dll\CgtFpNative.dll: Can't find dependent libraries . How could I resolve this ?Borst
I have gone through some so link and set the path also but still problem remains sameBorst
This doesn't work on my eclipse either any suggestions why?Stress
Q
11

I got this working.

For future reference:

Say the dll you need is in Y:\path\to\dlls\lib\. Then set your Run Configuration's working directory to Y:\path\to\dlls\ and set your VM arguments to include -Djava.library.path=lib.

That's it, it should now work. I don't know why specifying an absolute path in java.library.path didn't work previously, but setting a working directory seems to have done it.

Perhaps it's something peculiar to the specific library I'm using (or that Eclipse is running from a different drive than the library is on)...

Quintuplicate answered 20/6, 2012 at 22:13 Comment(1)
Well this worked for me while development. And if I'm using a .bat-file to run my program it works if the .dll files are in the same directory as the .jar file is. java -jar sample.jar But if I just want to start the .jar file without a .bat it seems it can't find the .dll files. Do I need to put them in a special folder to get my .jar file find them? I tried every folder-solution my mind came up with but nothing worked.Venezuela
D
0

I had similar issue but with Ghost Script dll. Even when followed placing the files in working directory and followed the instructions, it didn't work for me, refer the tag Ghost4J. java.lang.UnsatisfiedLinkError: Unable to load library 'gsdll64' and used the -Djna.library.path to get it worked.

Dogger answered 12/6, 2017 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.