在Linux上的Eclipse RCP应用程序中加载本机库 [英] Load native libraries in an Eclipse RCP application on Linux

查看:105
本文介绍了在Linux上的Eclipse RCP应用程序中加载本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Eclipse RCP应用程序,它通过JNI使用某些本机库。这些是彼此动态链接的共享库。在Windows上,我将这些库(作为 *。dll 文件)放在RCP启动器可执行文件( *。exe )旁边。文件并通过 System.load(<绝对文件路径>)加载它们。这很有用,因为启动器的位置似乎已添加到 java.library.path 中,以便库之间的动态链接有效。

I have an Eclipse RCP application that uses some native libraries via JNI. These are shared libraries that dynamically link to each other. On Windows I put these libraries (as *.dll files) next to the RCP launcher executable (*.exe) file and load them via System.load("<absolute file path>"). This works great, as the location of the launcher seems to be added to the java.library.path so that dynamic linking between the libraries works.

在Linux上,出现 UnsatisfiedLinkError 。启动器的位置未添加到 java.library.path 中。设置 LD_LIBRARY_PATH 变量后从终端启动应用程序时,它起作用:

On Linux, I get an UnsatisfiedLinkError. The location of the launcher is not added to the java.library.path. When I start the application from the terminal after setting the LD_LIBRARY_PATH variable it works:

export LD_LIBRARY_PATH=.
./myApp

位置被添加到 java.library.path 中。有一个更好的方法吗?我希望用户只需双击启动器。

The location . is the added to the java.library.path. Is there a better way to do this? I want the users to just double click the launcher.

-Djava.library.path =。中设置 myApp.ini 文件也不起作用。我在安装详细信息中看到了它,但仍然收到 UnsatisfiedLinkError

Setting -Djava.library.path=. in the myApp.ini file does also not work. I see it in the installation details but I still get an UnsatisfiedLinkError.

推荐答案

查找库的最可靠方法根本不是使用 java.library.path ,而是通过Java代码找到它们并通过 System.load加载()而不是 System.loadLibrary()。您可以应用所需的任何逻辑来查找本机库(尽管最好不要太聪明),并且可以尝试使用 java.library.path 您的机制失败了。

The most reliable way to find libraries is not using java.library.path at all but finding them via Java code and load via System.load() instead of System.loadLibrary(). You can apply whatever logic you want for finding the native library (although it's probably best trying not to be too clever) and you could fall back to trying java.library.path if your mechanism fails.

当然,只有在该库不依赖于其他可能找不到的库的情况下,这才起作用。

This will only work of course if the library doesn't depend on other libraries that might not be found.

这篇关于在Linux上的Eclipse RCP应用程序中加载本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆