如何从 Eclipse 设置 java.library.path
如何为整个 Eclipse 项目设置 java.library.path? 我正在使用依赖于操作系统特定文件的 Java 库,并且需要查找 .dll/
.so/
.jnilib
。 但应用程序总是退出并显示错误消息,指出在库路径上找不到这些文件。
我想配置整个项目以使用库路径。 我尝试将路径作为 VM 参数添加到 Eclipse 中的某些运行配置中,但这不起作用。
How can I set the java.library.path
for a whole Eclipse Project? I'm using a Java library that relies on OS specific files and need to find a .dll/
.so/
.jnilib
. But the Application always exits with an error message that those files are not found on the library path.
I would like to configure this whole project to use the library path. I tried to add the path as a VM argument to some run configurations in eclipse but that didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
另一个解决方案是打开“运行配置”,然后在“环境”选项卡中设置 {Path,Value} 组。
例如要添加位于项目根目录的“lib”目录,
Another solution would be to open the 'run configuration' and then in the 'Environment' tab, set the couple {Path,Value}.
For instance to add a 'lib' directory located at the root of the project,
请记住将本机库文件夹包含在 PATH 中。
Remember to include the native library folder in PATH.
我正在使用 Mac OS X Yosemite 和 Netbeans 8.02,我遇到了同样的错误,我找到的简单解决方案如上所示,当您需要在项目中包含本机库时,这非常有用。 因此,请为 Netbeans 做下一步:
我希望它对某人有用。
我找到解决方案的链接在这里:
java.library。路径 – 它是什么以及如何使用
I'm using Mac OS X Yosemite and Netbeans 8.02, I got the same error and the simple solution I have found is like above, this is useful when you need to include native library in the project. So do the next for Netbeans:
I hope it could be useful for someone.
The link where I found the solution is here:
java.library.path – What is it and how to use
有时我们无法通过直接右键单击项目来获取 Java 构建路径。
然后转到属性...
然后单击 java 构建路径
单击在选项卡上添加外部 jar 并给出存储 jar 的计算机文件的路径。
Sometime we dont get Java Build Path by directly right click on project.
then go to properties....
Then Click on java build path
Click on tab add external jars and give path of your computer file where u have stored jars.
这是另一个修复:
我的构建系统 (Gradle) 将所需的本机库 (dll) 添加到 Eclipse 构建路径(右键单击项目 -> 属性 -> Java 构建路径 -> 库)。 告诉构建系统不要将本机 dll 库添加到 Eclipse 类路径中解决了这个问题。
Here is another fix:
My build system (Gradle) added a required native library (dll) to the Eclipse build path (Right Click on Project -> Properties -> Java Build Path -> Libraries). Telling the build system not to add the native dll library to the Eclipse classpath solved the problem.
您可以在 Eclipse 中添加 vm 参数。
示例:
其中
cots_lib
是您的外部文件夹库。You can add vm argument in your Eclipse.
Example :
where
cots_lib
is your external folder library.最简单的方法是使用 eclipse IDE 本身。 转到菜单并设置构建路径。 使其指向目录中的 JAVA JDK 和 JRE 文件路径。 之后您可以检查将要设置编译文件的构建路径。 默认情况下在 bin 文件夹中。 最好的办法是允许 Eclipse 自行处理构建路径,并且仅对其进行编辑,类似于上面给出的解决方案
the easiest way would to use the eclipse IDE itself. Go to the menu and set build path. Make it point to the JAVA JDK and JRE file path in your directory. afterwards you can check the build path where compiled files are going to be set. in the bin folder by default though. The best thing would be to allow eclipse to handle itself the build path and only to edit it similar to the solution that is given above
不要弄乱库路径! Eclipse 自己构建!
相反,进入项目的库设置,对于需要本机库的每个 jar/etc,在“库”选项卡中展开它。 在树视图中,每个库都有源/javadoc 和本机库位置的项目。
具体为:选择
Project
,右键-> 属性 / Java构建路径 / 库选项卡,选择一个.jar,展开它,选择本机库位置,单击编辑,将出现文件夹选择器对话框)在命令行上弄乱库路径应该是您最后的努力,因为您可能会破坏 Eclipse 已经正确设置的内容。
Don't mess with the library path! Eclipse builds it itself!
Instead, go into the library settings for your projects and, for each jar/etc that requires a native library, expand it in the Libraries tab. In the tree view there, each library has items for source/javadoc and native library locations.
Specifically: select
Project
, right click -> Properties / Java Build Path / Libraries tab, select a .jar, expand it, select Native library location, click Edit, folder chooser dialog will appear)Messing with the library path on the command line should be your last ditch effort, because you might break something that is already properly set by eclipse.
如果将其添加为 VM 参数,请确保在其前面添加
-D
:If you are adding it as a VM argument, make sure you prefix it with
-D
:除了已批准的答案中描述的方法之外,如果您的项目中有单个本机库,还有另一种方法。
Except the way described in the approved answer, there's another way if you have single native libs in your project.
java.library.path
.对于给定的应用程序启动,您可以按照吉姆所说的那样进行。
如果您想为整个工作区设置它,您还可以在
每个 JRE 都有一个“默认 VM 参数”下设置它(我相信如果为运行配置设置了任何 VM 参数,则完全忽略它。)
您甚至可以设置不同的 JRE/JDK 具有不同的参数,并且有些项目使用一种,其他项目使用另一种。
For a given application launch, you can do it as jim says.
If you want to set it for the entire workspace, you can also set it under
Each JRE has a "Default VM arguments" (which I believe are completely ignored if any VM args are set for a run configuration.)
You could even set up different JRE/JDKs with different parameters and have some projects use one, other projects use another.
您只需将 -Djava.library.path=yourPath 添加到 eclipse.ini 即可。
You can simply add
-Djava.library.path=yourPath
to theeclipse.ini
.只需将
*.dll
文件添加到您的c:/windows
即可通过以下代码获取java.library.path:然后将您的dll文件添加到任意路径下你得到的
Just add the
*.dll
files to yourc:/windows
You can get the java.library.path from the follow codes:and then add you dll files under any path of you get
上述解决方案都不适合我(带有 JDK 1.7_015 的 Eclipse Juno)。 只有当我将库从project_folder/lib 移动到project_folder 时,Java 才能找到它们。
None of the solutions above worked for me (Eclipse Juno with JDK 1.7_015). Java could only find the libraries when I moved them from project_folder/lib to project_folder.
我认为想要设置 java.library.path 还有另一个原因。 Subversion 附带了许多库,除非可以附加
java.library.path
,否则 Eclipse 不会看到这些库。 例如,我使用的是 OS-X,因此库位于\opt\subversion\lib
下。 它们有很多,我想将它们保留在原处(而不是将它们复制到标准 lib 目录中)。项目设置无法解决此问题。
I think there is another reason for wanting to set
java.library.path
. Subversion comes with many libraries and Eclipse won't see these unlessjava.library.path
can be appended. For example I'm on OS-X, so the libraries are under\opt\subversion\lib
. There are a lot of them and I'd like to keep them where they are (not copy them into a standard lib directory).Project settings won't fix this.
单击“运行”
单击“调试...”
新的 Java 应用程序
单击“参数”选项卡
在第二个框(VM 参数)中添加 -D 条目
等...
Click Run
Click Debug ...
New Java Application
Click Arguments tab
in the 2nd box (VM Arguments) add the -D entry
etc...