Search code examples
javaeclipsedlllinkerjacob

Trouble adding a library to an Eclipse Project - UnsatisfiedLinkError


I'm trying to add the JACOB library to one of my java projects so that I can link up to iTunes and do some things with it.

I've followed the instructions at this link: http://www.dreamincode.net/forums/topic/96304-how-to-add-dll-files-in-javalibrarypath/


They are the following:

Build Path > Configure Build Path...

Click on the button "Add Library"

choose "User Library"

Next

Click the 'User Libraries...' button

Click 'New'

Give it a name 'JACOB Library' -- press ok

Click on new library and press "Add Jars"

Locate the jacob.jar and click ok

expand the library (the little +) and click on Native Library location and add the location of the DLL. (you may also want to attach source and java docs for jacob as this may help you with debugging).

Press OK

Select the library -- Press Finnish -- Press OK


The program compiles and runs fine in eclipse, but when I export it to a runnable JAR file choosing the option "Extract required libraries into generated JAR" it gives me the following exception:

Exception in thread "Dummy Thread" java.lang.UnsatisfiedLinkError: no jacob-1.18-M2-x64 in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at com.jacob.com.LibraryLoader.loadJacobLibrary(LibraryLoader.java:184)
    at com.jacob.com.JacobObject.<clinit>(JacobObject.java:107)
    at Build.Test.process(Test.java:181)
    at Build.Test.listen(Test.java:226)
    at Build.DummyThread.run(DummyThread.java:29)
    at java.lang.Thread.run(Unknown Source)

What else do I have to do to get this to work? Thanks for any help ahead of time.


Solution

  • The library (on Windows, a DLL) must be in a directory somewhere on your PATH or on a path listed in the java.library.path system property (so you can launch Java like java -Djava.library.path=/path/to/dir).

    Additionally, for loadLibrary(), you specify the base name of the library, without the .dll at the end. So, for /path/to/something.dll, you would just use System.loadLibrary("something").

    See this (Mac example)