UnsatisfiedLinkError with sqlite4java Jar on Mac OS X

天大地大妈咪最大 提交于 2019-12-19 04:06:20

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14301562/unsatisfiedlinkerror-with-sqlite4java-jar-on-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!