简体   繁体   English

在Mac OS X上使用sqlite4java Jar的UnsatisfiedLinkError

[英]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. 我在我的Java应用程序中使用sqlite4java库,当我在Eclipse中运行它时,它工作得很好。 But when I build the runnable JAR and try to run it on Mac OS X, I get the following error: 但是当我构建可运行的JAR并尝试在Mac OS X上运行它时,我收到以下错误:

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. 即使我选择“将所需的库打包到生成的JAR中”,也会发生这种情况,这应该会复制我需要的所有文件。 Why isn't this working? 为什么这不起作用?

Unlike many other dependencies, sqlite4java uses additional files based on the host platform to interface with SQLite databases. 与许多其他依赖项不同,sqlite4java使用基于主机平台的其他文件与SQLite数据库进行交互。 When Eclipse packages the required libraries, it only copies the sqlite4java.jar file, but not the other required files. 当Eclipse打包所需的库时,它只复制sqlite4java.jar文件,而不复制其他所需的文件。

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. 您可能认为解决方案是使用“将所需的库复制到生成的JAR旁边的子文件夹”选项导出可运行的JAR文件,并手动添加丢失的文件,但是,这似乎不起作用。

The best solution I've found is actually the most Mac-friendly one. 我发现的最佳解决方案实际上是最适合Mac的解决方案。 Instead of exporting as a runnable JAR file, you export as a Mac OS X application bundle! 您可以导出为Mac OS X应用程序包,而不是导出为可运行的JAR文件! To do that in Eclipse: 要在Eclipse中执行此操作:

  1. Go to "File" –> "Export…" 转到“文件” - >“导出...”
  2. Under the "Other" folder, choose "Mac OS X application bundle" 在“其他”文件夹下,选择“Mac OS X应用程序包”
  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) 在“添加到捆绑包”部分下,在“添加到类路径”部分的SQLite下载中添加“libsqlite4java-osx.jnilib”文件(您还可以添加libsqlite4java-osx-10.4.jnilib和libsqlite4java-osx-ppc。 jnilib如果你支持传统硬件)
  5. Click "Finish" 点击“完成”

You'll now have a Mac OS X application that properly loads sqlite4java. 您现在将拥有一个正确加载sqlite4java的Mac OS X应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM