如何将本机库添加到“java.library.path” 随着 Eclipse 启动(而不是覆盖它)
我有一个本机库需要添加到java.library.path。 使用 JVM 参数 -Djava.library.path=path... 我可以根据需要设置路径。
我的问题是我的其他库(pentaho reporting)根据默认的 java.library.path (包括系统目录等)搜索字体,并且手动设置覆盖默认路径。
所以:我如何添加 默认 java.library.path 的路径条目而不是覆盖它(这似乎是用 -Djava.library.path 完成的)? (我不想手动添加默认路径,这对于部署来说不太好)
编辑:抱歉缺少详细信息; 我正在使用 Eclipse。 (部署是使用 JNLP 完成的,我可以在资源下使用nativelib)
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.
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..
So : how can I add a 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)
EDIT: Sorry for missing details; I'm working with Eclipse. (The deployment is done with JNLP and there I can use nativelib under resources)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
忘记了这个问题...我实际上是在用 Eclipse 询问,很抱歉最初没有说明这一点。
答案似乎太简单了(至少对于 3.5 来说;可能对于旧版本也是如此):
Java 运行配置的参数:VM 参数:
一定不要忘记引号,否则 PATH 中的空格会出现问题。
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):
Java run configuration's Arguments : VM arguments:
Must not forget the quotation marks, otherwise there are problems with spaces in PATH.
如果您想在 Eclipse 中开发时添加本机库而不干扰
java.library.path
(以避免包含绝对路径并必须向启动配置添加参数),您可以提供路径到本机库位置下的Java构建路径对话框中每个Jar的本机库位置。 请注意,本机库文件名必须与 Jar 文件名相对应。 另请参阅此详细说明。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 Path dialog under Native library location. Note that the native library file name has to correspond to the Jar file name. See also this detailed description.SWT 将必要的本机 DLL 放入 JAR 中。 搜索“org.eclipse.swt.win32.win32.x86_3.4.1.v3449c.jar”作为示例。
DLL 必须位于 JAR 的根目录中,JAR 必须经过签名,并且 DLL 必须带有校验和出现在 META-INF/MANIFEST.MF 中,以便 VM 获取它们。
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.
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.
在 Windows 中,如下所示:
-Djava.library.path="C:/MyLibPath;%PATH%"
%PATH%
是旧的-Djava.library .路径
In Windows, like this:
-Djava.library.path="C:/MyLibPath;%PATH%"
%PATH%
is your old-Djava.library.path
您可以通过调用 System.load() 以编程方式加载您的本机库? 此方法(与 System.loadLibrary()) 允许您指定绝对路径。
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.
在 UNIX 系统中,您可以附加到 LD_LIBRARY_PATH 环境变量。 在 Windows 上,JVM 自动将系统属性 java.library.path 设置为 PATH; 所以如果 dll 在你的 PATH 中,那么你就设置好了。
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.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=102239 指出 Eclipse 的启动器中没有实现替换机制,至少在发布 Juno 之前没有。
因此,在启动 Eclipse 时,如果事先不了解默认设置,就(几乎)不可能将另一个库文件夹追加或添加到 java.library.path 中。
我写得差不多了,因为应该可以用一个命令让 Eclipse 启动、转储 java.library.path 的内容并停止 Eclipse。 转储将被解析,然后作为启动 Eclipse 的输入,即
https://bugs.eclipse.org/bugs/show_bug.cgi?id=102239 states that there is no substitution mechanics implemented in Eclipse's launcher, at least no up to release Juno.
Thus it is (almost) impossible to append or prepend another library folder to java.library.path when launching Eclipse without prior knowledge of the default setting.
I wrote almost, cause it should be possible to let Eclipse startup, dump the content of java.library.path and stop Eclipse in one command. The dump would the be parsed and then taken as the input for launching Eclipse, i.e.
java.library.path
使用上面变量在相应平台上的值进行初始化。这应该适用于任何 IDE。
您可以通过调用 java -XshowSettings:properties 来测试该值是否是您期望的值
java.library.path
is initilized with the values of the variables above on its corresponding platform.This should work on any IDE.
You can test if the value is what you expect by calling
java -XshowSettings:properties
Rob Elsner 在上述评论之一中提供的解决方案运行完美(OSX 10.9,Eclipse Kepler)。 必须将其附加路径附加到由“:”分隔的路径。
The solution offered by Rob Elsner in one of the comments above works perfectly (OSX 10.9, Eclipse Kepler). One has to append their additional paths to that separated by ":".
窗口 -> 首选项 -> Java -> 安装的 JRE
。JRE(JDK),然后单击编辑。
-Djava.library.path=/usr/local/xuggler/lib
。Window->Preferences->Java->Installed JREs
.JRE(JDK) and click Edit.
-Djava.library.path=/usr/local/xuggler/lib
.本机库文件名必须与 Jar 文件名相对应。 这是非常非常重要的。
请确保 jar 名称和 dll 名称相同。
另外,请参阅 Fabian Steeg 的帖子
我下载的 jamin 包含不同名称的 dll 和 jar。
它是jawin.jar和jawind.dll,注意dll文件名中额外的“d”。
我只是将其重命名为 jamin.dll 并将其设置为 eclipse 中的本机库,如帖子中所述
“http://www.eclipsezone.com/eclipse/forums/t49342.html”
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"
由于某种原因,我无法让多个文件夹工作(有一段时间确实如此,但一旦我需要更多 dll 并添加更多文件夹,路径中没有空格)。 然后,我将所有需要的 dll 复制到一个文件夹,并将其作为我的 java.library.path 并且它起作用了。 我没有解释——如果有人能解释,那就太好了。
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.path and it worked. I don't have an explanation - if anyone does, it would be great.
许多现有答案假设您想要为特定项目设置此选项,但我需要为 Eclipse 本身设置它,以支持 SQL Server JDBC 驱动程序的集成身份验证。
为此,我按照这些说明从 Java 命令行而不是普通启动器启动 Eclipse。 然后我修改了该脚本以将 -Djava.library.path 参数添加到 Java 命令行。
Many of the existing answers assume you want to set this for a particular project, but I needed to set it for Eclipse itself in order to support integrated authentication for the SQL Server JDBC driver.
To do this, I followed these instructions for launching Eclipse from the Java commandline instead of its normal launcher. Then I just modified that script to add my -Djava.library.path argument to the Java commandline.
在 Windows 上,我发现重要的是从命令行启动 Eclipse,而不是从“开始”菜单或快捷方式启动,前提是本机 DLL 位于 PATH 中的目录中。 显然,这可以确保正确的目录位于路径上。
On Windows, I have found that the important thing is to start Eclipse from the command line rather 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.