如何使用 Eclipse 启动将本机库添加到“java.library.path”(而不是覆盖它)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/661320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add native library to "java.library.path" with Eclipse launch (instead of overriding it)
提问by Touko
I got a native library that needs to be added to java.library.path. With JVM argument -Djava.library.path=path...I can set the path as I want.
我有一个需要添加到java.library.path的本机库。使用 JVM 参数-Djava.library.path=path...我可以根据需要设置路径。
My problem is that my other library (pentaho reporting) searches fonts based on the default java.library.path (including system directories etc) and the manual setting overrides the default path..
我的问题是我的其他库(pentaho 报告)根据默认的 java.library.path(包括系统目录等)搜索字体,并且手动设置覆盖了默认路径。
So : how can I adda path entry to the default java.library.path instead of overriding it (which seems to be done with -Djava.library.path)? (I wouldn't want to add the default path by hand, which wouldn't be nice for the sake of deployment)
所以:如何将路径条目添加到默认的 java.library.path 而不是覆盖它(这似乎是用 -Djava.library.path 完成的)?(我不想手动添加默认路径,这对于部署来说不太好)
EDIT: Sorry for missing details; I'm working with Eclipse. (The deployment is done with JNLP and there I can use nativelibunder resources)
编辑:抱歉缺少细节;我正在使用 Eclipse。(部署是用 JNLP 完成的,我可以在资源下使用 nativelib)
采纳答案by Touko
Had forgotten this issue... I was actually asking with Eclipse, sorry for not stating that originally. And the answer seems to be too simple (at least with 3.5; probably with older versions also):
已经忘记了这个问题......我实际上是在用 Eclipse 询问,抱歉最初没有说明这一点。答案似乎太简单了(至少在 3.5 中;可能还有旧版本):
Java run configuration's Arguments : VM arguments:
Java 运行配置的参数:VM 参数:
-Djava.library.path="${workspace_loc:project}\lib;${env_var:PATH}"
Must not forget the quotation marks, otherwise there are problems with spaces in PATH.
一定不要忘记引号,否则PATH中的空格有问题。
回答by Simon Nickerson
Can you get round this by calling System.load() programmatically to load your native library? This method (unlike System.loadLibrary()) allows you to specify an absolute path.
你能通过以编程方式调用System.load()来加载你的本地库来解决这个问题吗?此方法(与System.loadLibrary()不同)允许您指定绝对路径。
回答by Aaron Digulla
SWT puts the necessary native DLLs into a JAR. Search for "org.eclipse.swt.win32.win32.x86_3.4.1.v3449c.jar" for an example.
SWT 将必要的本机 DLL 放入 JAR 中。例如,搜索“org.eclipse.swt.win32.win32.x86_3.4.1.v3449c.jar”。
The DLLs must be in the root of the JAR, the JAR must be signed and the DLL must appear with checksum in the META-INF/MANIFEST.MF for the VM to pick them up.
DLL 必须位于 JAR 的根目录中,必须对 JAR 进行签名,并且 DLL 必须与校验和一起出现在 META-INF/MANIFEST.MF 中,以便 VM 获取它们。
回答by andy boot
In Windows, like this:
在 Windows 中,像这样:
-Djava.library.path="C:/MyLibPath;%PATH%"
-Djava.library.path="C:/MyLibPath;%PATH%"
%PATH% is your old -Djava.library.path
%PATH% 是你的旧 -Djava.library.path
回答by geowa4
In UNIX systems, you can append to the LD_LIBRARY_PATH environment variable. On Windows, the JVM automatically sets the system property, java.library.path, to PATH; so if the dll is on your PATH, then you're set.
在 UNIX 系统中,您可以附加到 LD_LIBRARY_PATH 环境变量。在 Windows 上,JVM 自动将系统属性 java.library.path 设置为 PATH;所以如果dll在你的PATH上,那么你就设置好了。
回答by Fabian Steeg
If you want to add a native library without interfering with java.library.path
at development time in Eclipse (to avoid including absolute paths and having to add parameters to your launch configuration), you can supply the path to the native libraries location for each Jar in the Java Build Pathdialog under Native library location. Note that the native library file name has to correspond to the Jar file name. See also this detailed description.
如果您想java.library.path
在 Eclipse 中的开发时添加本地库而不干扰(以避免包括绝对路径和必须向启动配置添加参数),您可以在Java Build 中为每个 Jar 提供本地库位置的路径本机库位置下的路径对话框。请注意,本机库文件名必须与 Jar 文件名相对应。另请参阅此详细说明。
回答by Dhana
The native library file name has to correspond to the Jar file name. This is very very important. Please make sure that jar name and dll name are same. Also,please see the post from Fabian Steeg My download for jawin was containing different names for dll and jar. It was jawin.jar and jawind.dll, note extra 'd' in dll file name. I simply renamed it to jawin.dll and set it as a native library in eclipse as mentioned in post "http://www.eclipsezone.com/eclipse/forums/t49342.html"
本机库文件名必须与 Jar 文件名相对应。这是非常非常重要的。请确保 jar 名称和 dll 名称相同。另外,请参阅 Fabian Steeg 的帖子我的jawin 下载包含不同的 dll 和 jar 名称。它是jawin.jar 和jawin d.dll,注意dll 文件名中的额外'd'。我只是将其重命名为jawin.dll 并将其设置为 eclipse 中的本机库,如帖子“ http://www.eclipsezone.com/eclipse/forums/t49342.html”中所述
回答by Vadym
Window->Preferences->Java->Installed JREs. Then choose your current JRE(JDK) and click Edit. Fill Default VM Arguments: -Djava.library.path=/usr/local/xuggler/lib. Done!
Window->Preferences->Java->Installed JREs。然后选择您当前的 JRE(JDK) 并单击编辑。填写默认 VM 参数:-Djava.library.path=/usr/local/xuggler/lib。完毕!
回答by Ustaman Sangat
For some reason I couldn't get multiple folders to work (well it did for a while but as soon as I needed more dlls and added more folders, none with white spaces in the path). I then copied all needed dlls to one folder and had that as my java.library.pathand it worked. I don't have an explanation - if anyone does, it would be great.
出于某种原因,我无法让多个文件夹工作(它确实有一段时间了,但是一旦我需要更多 dll 并添加更多文件夹,路径中没有空格)。然后我将所有需要的 dll 复制到一个文件夹中,并将其作为我的java.library.path并且它起作用了。我没有解释——如果有人解释,那就太好了。
回答by Alan
On Windows, I have found that the important thing is to start Eclipse from the command linerather than from the Start Menu or a shortcut, provided that the native DLL is in a directory in your PATH. Apparently, this ensures that the proper directory is on the path.
在 Windows 上,我发现重要的是从命令行而不是从开始菜单或快捷方式启动 Eclipse,前提是本机 DLL 位于您的 PATH 目录中。显然,这确保了正确的目录在路径上。