2

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.

Riptyde4
  • 5,134
  • 8
  • 30
  • 57
  • Check Jacob jar exists into your runnable Jar, unzip it, and locate Jacob into lib folder for sure. – 0x5a4d Mar 28 '15 at 00:38
  • @0x5a4d See this screenshot I uploaded: http://s7.postimg.org/akywjfasp/Untitled_1.jpg Is it because its com/jacob/com/...? Should it be stored as com/jacob/... – Riptyde4 Mar 28 '15 at 00:50
  • what OS are you use? – 0x5a4d Mar 28 '15 at 01:22
  • @0x5a4d It seems jacob.jar does not exist in the runnable jar, but the library folder does – Riptyde4 Mar 28 '15 at 01:24
  • OK. What System.out.println(System.getProperty("java.library.path")); printing? – 0x5a4d Mar 28 '15 at 01:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73977/discussion-between-0x5a4d-and-riptyde4). – 0x5a4d Mar 28 '15 at 01:27
  • @0x5a4d C:\Program Files (x86)\Java\jacob-1.18-M2\lib;C:\Users\Jonathan\Desktop\iTunes Clapper\iTunes Library;C:\java\jre7\lib ... The /lib/ folder in the jacob-1.18-M2 directory contains my DLL files. – Riptyde4 Mar 28 '15 at 01:28
  • 1
    DLL needs to be in the current working directory or in a directory listed in the Windows PATH environment variable.Java looks for jars under classpath, and libraries under path – 0x5a4d Mar 28 '15 at 01:31
  • @0x5a4d If i place it in the current working directory what do I set the native library location to for the user library? – Riptyde4 Mar 28 '15 at 01:32
  • @0x5a4d I placed it into the current working directory, it works! thanks. – Riptyde4 Mar 28 '15 at 01:38

1 Answers1

1

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)

0x5a4d
  • 750
  • 1
  • 7
  • 21