如何从 Eclipse 设置 java.library.path

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/957700/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:34:54  来源:igfitidea点击:

How to set the java.library.path from Eclipse

javaeclipseconfigurationbuildpath

提问by Janusz

How can I set the java.library.pathfor 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.

如何java.library.path为整个 Eclipse 项目设置?我正在使用一个依赖于操作系统特定文件的 Java 库,需要找到一个.dll/.so/.jnilib. 但是应用程序总是退出并显示一条错误消息,指出在库路径中找不到这些文件。

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.

我想将整个项目配置为使用库路径。我尝试将路径作为 VM 参数添加到 eclipse 中的某些运行配置中,但这不起作用。

采纳答案by John Gardner

Don't mess with the library path! Eclipse builds it itself!

不要弄乱库路径!Eclipse 自己构建它!

Instead, go into the library settings for your projects and, for each jar/etc that requires a native library, expand it in the Librariestab. In the tree view there, each library has items for source/javadoc and native library locations.

相反,进入项目的库设置,对于需要本机库的每个 jar/etc,在选项卡中展开它。在那里的树视图中,每个库都有源/javadoc 和本机库位置的项目。

Specifically: select Project, right click -> Properties/ Java Build Path/ Librariestab, select a .jar, expand it, select Native library location, click Edit, folder chooser dialog will appear)

具体:选择Project,右键->属性/ Java构建路径/选项卡,选择一个.jar,展开,选择Native library location,点击Edit,会出现文件夹选择对话框)

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.

在命令行上弄乱库路径应该是你最后的努力,因为你可能会破坏 eclipse 已经正确设置的东西。

Native library location

本地库位置

回答by matt b

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

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

-Djava.library.path=blahblahblah...

回答by jim

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

单击运行
单击调试...
新建 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  

etc...

等等...

回答by Scott Stanchfield

For a given application launch, you can do it as jim says.

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

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.)

每个 JRE 都有一个“默认 VM 参数”(如果为运行配置设置了任何 VM 参数,我相信它会被完全忽略。)

You could even set up different JRE/JDKs with different parameters and have some projects use one, other projects use another.

您甚至可以使用不同的参数设置不同的 JRE/JDK,让一些项目使用一个,其他项目使用另一个。

回答by sonaht

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

您可以简单地添加-Djava.library.path=yourPatheclipse.ini.

回答by Mr Lou

Just add the *.dllfiles to your c:/windows

只需将*.dll文件添加到您的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

你可以从下面的代码中得到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"));
    }
}

回答by schieferstapel

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.
  • 在 Project properties->Java Build Path->Tab "Source" 中有一个源文件夹列表
  • 对于每个条目,都有“本机库位置”,它也支持工作区中的路径。
  • 这将使 Eclipse 将其添加到您的java.library.path.

回答by user825628

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.pathcan 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).

我认为想要设置java.library.path. Subversion 带有许多库,除非java.library.path可以附加,否则 Eclipse 不会看到这些库。例如我在 OS-X 上,所以库在\opt\subversion\lib. 它们有很多,我想将它们保留在原处(不要将它们复制到标准 lib 目录中)。

Project settings won't fix this.

项目设置不会解决这个问题。

回答by Aurelien

Another solution would be to open the 'run configuration' and then in the 'Environment' tab, set the couple {Path,Value}.

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

For instance to add a 'lib' directory located at the root of the project,

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

    Path  <-  ${workspace_loc:name_of_the_project}\lib

回答by Günter

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.

上述解决方案都不适用于我(Eclipse Juno with JDK 1.7_015)。当我将它们从 project_folder/lib 移动到 project_folder 时,Java 只能找到这些库。