Java - Linux 上的 java.library.path 问题
我能够在我的 mac 上从 cmd 行运行一个具有一些依赖项的 java 程序,但是当我尝试在 linux SUSE 11 机器上运行它时,我得到它:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no myNativeLib in java.library.path
这是我正在运行的 cmd 行:
java -Djava.library.path=../lib -cp ../jar/a-jar.jar:. MyMainClass
感谢任何帮助!
I am able to run a java program with some dependencies from cmd line on my mac, but when I try to run it on a linux SUSE 11 box I have it comes back with:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no myNativeLib in java.library.path
This is the cmd line I am running:
java -Djava.library.path=../lib -cp ../jar/a-jar.jar:. MyMainClass
Any help appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议对 java.library.path 使用绝对路径。至少您可以消除相对路径解析可能出现的问题。
另外,只是为了确认一下,你的 lib 中确实有 Linux 库,对吧? Mac 一台不行。
I would recommend to use absolute path for
java.library.path
. At least you eliminate possible problems with relative path resolution.Also, just to confirm, you do have Linux library in the lib, right? Mac one will not work.
我将冒险假设(冒着大量反对票的风险)您正在尝试使用 Oracle 的本机数据库驱动程序。
如果您使用的确实是数据库驱动程序,则可以放弃本机版本,只需使用 -cp 扩展名将 .jar 瘦客户端包含在您的类路径中。这可能需要更改一些代码,这样您就不会尝试调用本机驱动程序。
如果您一心想要使用本机驱动程序,或者您需要这样做,因为代码依赖于它。您需要确保 java.library.path 变量设置为包含二进制驱动程序文件的目录(通常用 .so 扩展名表示)。
还要确保这些驱动程序文件(因为它们是本机二进制文件)已针对您的 Linux 发行版进行了编译,而不仅仅是从 mac 安装中方便地复制。
如果您没有做任何这些事情,请随意忽略我所说的一切。
I'm going go out on a limb and assume(at the risk of a bunch of downvotes) that you are trying to use oracle's native database driver.
If it is indeed a database driver that you are using, you can bail on the native version and simply include the .jar thin client on your classpath by using the -cp extension. This may require some code changes such that you are not attempting to invoke the native driver.
If you are hell bent on using a native driver or you need to because the code relies on it. you need to make sure that the java.library.path variable is set to a directory containing the binary driver files(typically denoted with a .so extension).
Also make sure these driver files(since they are native binary) have been compiled for your distribution of linux and not just conveniently copied from the mac install.
If you are not doing any of these things feel free to ignore everything I've said.