Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

-Djava.library.path=blahblahblah...

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.

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.

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

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"));
    }
}

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.

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.

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

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

Remember to include the native library folder in PATH.

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

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.

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.

you can add vm argument in your eclipse.

Example : -Djava.ext.dirs=cots_lib

where cots_lib is your external folder library.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top