如何从 Eclipse 设置 java.library.path

发布于 2024-07-23 11:17:24 字数 244 浏览 17 评论 0原文

如何为整个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

世界如花海般美丽 2024-07-30 11:17:25

另一个解决方案是打开“运行配置”,然后在“环境”选项卡中设置 {Path,Value} 组。

例如要添加位于项目根目录的“lib”目录,

    Path  <-  ${workspace_loc:name_of_the_project}\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  <-  ${workspace_loc:name_of_the_project}\lib
女中豪杰 2024-07-30 11:17:25

请记住将本机库文件夹包含在 PATH 中。

Remember to include the native library folder in PATH.

旧竹 2024-07-30 11:17:25

我正在使用 Mac OS X Yosemite 和 Netbeans 8.02,我遇到了同样的错误,我找到的简单解决方案如上所示,当您需要在项目中包含本机库时,这非常有用。 因此,请为 Netbeans 做下一步:

1.- Right click on the Project
2.- Properties
3.- Click on RUN
4.- VM Options: java -Djava.library.path="your_path"
5.- for example in my case: java -Djava.library.path=</Users/Lexynux/NetBeansProjects/NAO/libs>
6.- Ok

我希望它对某人有用。
我找到解决方案的链接在这里:
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:

1.- Right click on the Project
2.- Properties
3.- Click on RUN
4.- VM Options: java -Djava.library.path="your_path"
5.- for example in my case: java -Djava.library.path=</Users/Lexynux/NetBeansProjects/NAO/libs>
6.- Ok

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

a√萤火虫的光℡ 2024-07-30 11:17:25

有时我们无法通过直接右键单击项目来获取 Java 构建路径。
然后转到属性... 右键单击并转到属性

然后单击 java 构建路径Properties Scrren

单击添加外部 jar

单击在选项卡上添加外部 jar 并给出存储 jar 的计算机文件的路径。

Sometime we dont get Java Build Path by directly right click on project.
then go to properties.... Right Click and go to properties

Then Click on java build pathProperties Scrren

Click on add external jar

Click on tab add external jars and give path of your computer file where u have stored jars.

黑寡妇 2024-07-30 11:17:25

这是另一个修复:

我的构建系统 (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.

莳間冲淡了誓言ζ 2024-07-30 11:17:25

您可以在 Eclipse 中添加 vm 参数。

示例:

-Djava.ext.dirs=cots_lib

其中 cots_lib 是您的外部文件夹库。

You can add vm argument in your Eclipse.

Example :

-Djava.ext.dirs=cots_lib

where cots_lib is your external folder library.

国粹 2024-07-30 11:17:25

最简单的方法是使用 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

盛装女皇 2024-07-30 11:17:24

不要弄乱库路径! 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.

Native library location

故乡的云 2024-07-30 11:17:24

如果将其添加为 VM 参数,请确保在其前面添加 -D

-Djava.library.path=blahblahblah...

If you are adding it as a VM argument, make sure you prefix it with -D:

-Djava.library.path=blahblahblah...
浅唱ヾ落雨殇 2024-07-30 11:17:24

除了已批准的答案中描述的方法之外,如果您的项目中有单个本机库,还有另一种方法。

  • 在项目属性 -> Java 构建路径 -> 选项卡“源”中,有一个源文件夹列表
  • 对于每个条目,都有“本机库位置”,它也支持工作区中的路径。
  • 这将使 Eclipse 将其添加到您的 java.library.path 中。

Except the way described in the approved answer, there's another way if you have single native libs in your project.

  • in Project properties->Java Build Path->Tab "Source" there's a list of your source-folders
  • For each entry, there's "Native library locations", which also supports paths within the workspace.
  • This will make Eclipse add it to your java.library.path.
鲜血染红嫁衣 2024-07-30 11:17:24

对于给定的应用程序启动,您可以按照吉姆所说的那样进行。

如果您想为整个工作区设置它,您还可以在

Window->
  Preferences->
    Java->
      Installed JREs

每个 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

Window->
  Preferences->
    Java->
      Installed JREs

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.

过气美图社 2024-07-30 11:17:24

您只需将 -Djava.library.path=yourPath 添加到 eclipse.ini 即可。

You can simply add -Djava.library.path=yourPath to the eclipse.ini.

绮烟 2024-07-30 11:17:24

只需将*.dll文件添加到您的c:/windows

即可通过以下代码获取java.library.path:然后将您的dll文件添加到任意路径下你得到的

import java.util.logging.Logger;

public class Test {


    static Logger logger = Logger.getLogger(Test.class.getName());
    public static void main(String[] args) {
    logger.info(System.getProperty("java.library.path"));
    }
}

Just add the *.dll files to your c:/windows

You can get the java.library.path from the follow codes:and then add you dll files under any path of you get

import java.util.logging.Logger;

public class Test {


    static Logger logger = Logger.getLogger(Test.class.getName());
    public static void main(String[] args) {
    logger.info(System.getProperty("java.library.path"));
    }
}
假装爱人 2024-07-30 11:17:24

上述解决方案都不适合我(带有 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.

嗼ふ静 2024-07-30 11:17:24

我认为想要设置 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 unless java.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.

冷…雨湿花 2024-07-30 11:17:24

单击“运行”
单击“调试...”
新的 Java 应用程序
单击“参数”选项卡
在第二个框(VM 参数)中添加 -D 条目

-Xdebug -verbose:gc -Xbootclasspath/p:jar/vbjorb.jar;jar/oracle9.jar;classes;jar/mq.jar;jar/xml4j.jar -classpath -DORBInitRef=NameService=iioploc://10.101.2.94:8092/NameService  

等...

Click Run
Click Debug ...
New Java Application
Click Arguments tab
in the 2nd box (VM Arguments) add the -D entry

-Xdebug -verbose:gc -Xbootclasspath/p:jar/vbjorb.jar;jar/oracle9.jar;classes;jar/mq.jar;jar/xml4j.jar -classpath -DORBInitRef=NameService=iioploc://10.101.2.94:8092/NameService  

etc...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文