3

I'm using the sqlite4java library in my Java application and it works just fine when I'm running it in Eclipse. But when I build the runnable JAR and try to run it on Mac OS X, I get the following error:

Error: Could not load database file. 
Error: com.almworks.sqlite4java.SQLiteException: [-91] cannot load library:
java.lang.UnsatisfiedLinkError: no sqlite4java-osx-x86_64 in java.library.path

This happens even when I select "Package required libraries into generated JAR", which supposedly copies over all of the files I need. Why isn't this working?

Thunderforge
  • 19,637
  • 18
  • 83
  • 130
  • you can find the solution on : [http://stackoverflow.com/questions/15559551/unsatisfiedlinkerror-with-sqlite4java-jar-on-mac-os-x-netbeans/22099958#22099958][1] [1]: http://stackoverflow.com/questions/15559551/unsatisfiedlinkerror-with-sqlite4java-jar-on-mac-os-x-netbeans/22099958#22099958 – A.KAMMOUN Feb 28 '14 at 16:22
  • @7allouf, that solution recommends putting the library in Java/Extensions which may not always be practical, for instance, if distributing to a client. It's not a bad solution for a developer using an IDE, but it may not be the right one for a distributed application. – Thunderforge Feb 28 '14 at 16:44
  • You can see this play out in this other Stack Overflow answer, which also covers how to programatically set `java.library.path` if needed: http://stackoverflow.com/a/35353377/3679676 – Jayson Minard Feb 12 '16 at 03:03

1 Answers1

0

Unlike many other dependencies, sqlite4java uses additional files based on the host platform to interface with SQLite databases. When Eclipse packages the required libraries, it only copies the sqlite4java.jar file, but not the other required files.

You might think that the solution would be to export the runnable JAR file with the option "Copy required libraries into a sub-folder next to the generated JAR" and manually add the missing files, but alas, that doesn't seem to work either.

The best solution I've found is actually the most Mac-friendly one. Instead of exporting as a runnable JAR file, you export as a Mac OS X application bundle! To do that in Eclipse:

  1. Go to "File" –> "Export…"
  2. Under the "Other" folder, choose "Mac OS X application bundle"
  3. Fill out the first screen and click "Next"
  4. Under the "Add to Bundle" section, add the "libsqlite4java-osx.jnilib" file from your SQLite download in the "Add to Classpath" section (you can also add libsqlite4java-osx-10.4.jnilib and libsqlite4java-osx-ppc.jnilib if you're supporting legacy hardware)
  5. Click "Finish"

You'll now have a Mac OS X application that properly loads sqlite4java.

Thunderforge
  • 19,637
  • 18
  • 83
  • 130