How to set the java.library.path from Eclipse

2018-12-31 07:00发布

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.

16条回答
唯独是你
2楼-- · 2018-12-31 07:31

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.
查看更多
公子世无双
3楼-- · 2018-12-31 07:33

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

查看更多
伤终究还是伤i
4楼-- · 2018-12-31 07:34

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

查看更多
回忆,回不去的记忆
5楼-- · 2018-12-31 07:35

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

查看更多
长期被迫恋爱
6楼-- · 2018-12-31 07:36

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.

查看更多
只若初见
7楼-- · 2018-12-31 07:37

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"));
    }
}
查看更多
登录 后发表回答