Java “本机库位置”条目在 Eclipse 中有什么作用?

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

What does "Native library location" entry do in Eclipse?

javaeclipsejava-native-interfacenative

提问by Suzan Cioc

If adding user-defined library in Eclipse, one has an ability to set "Native library location". This field allows to enter some directory path.

如果在 Eclipse 中添加用户定义的库,则可以设置“本机库位置”。该字段允许输入一些目录路径。

When does this path plays a part?

这条道路什么时候发挥作用?

采纳答案by Aaron Digulla

Eclipse uses this information to build the java.library.pathwhen it launches a Java program.

Eclipsejava.library.path在启动 Java 程序时使用此信息来构建。

Background: Some Java frameworks depend on native code. This code usually comes in the form of a native shared library (*.so, *.dll). In Java, you can see methods with the attribute native. The code will load the shared library using System.loadLibrary().

背景:一些 Java 框架依赖于本机代码。此代码通常以本机共享库(*.so、*.dll)的形式出现。在 Java 中,您可以看到带有属性的方法native。代码将使用System.loadLibrary().

In order to make the code independent of absolute paths, you just pass the name of the shared library to System.loadLibrary(). The System property java.library.pathis then used to determine in which directories the VM should look to locate the file.

为了使代码独立于绝对路径,您只需将共享库的名称传递给System.loadLibrary(). 然后,系统属性java.library.path用于确定 VM 应在哪些目录中查找文件。

Together with Eclipse's feature to define user libraries, you can easily add Java libraries that depend on native code to your projects.

结合 Eclipse 定义用户库的特性,您可以轻松地将依赖于本机代码的 Java 库添加到您的项目中。

回答by McDowell

Are you referring to the Java Build Pathconfiguration?

你指的是Java Build Path配置吗?

You may need this location if your project uses JNIor JNA. This directory is the location of native code (e.g. a Windows DLL written in C.)

如果您的项目使用JNIJNA,您可能需要此位置。该目录是本机代码(例如用 C 编写的 Windows DLL)的位置。

I don't think this information is actually required until you try to run the code. You could provide this information via the Run Configurationfor example.

在您尝试运行代码之前,我认为实际上不需要这些信息。例如,您可以通过运行配置提供此信息。