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

Robbie Rosati picture Robbie Rosati · Jun 20, 2012 · Viewed 67.1k times · Source

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}"

Answer

Wayne picture Wayne · Feb 1, 2013

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