Search code examples
javamacosunsatisfiedlinkerror

UnsatisfiedLinkError with sqlite4java Jar on Mac OS X


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?


Solution

  • 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.