How to set the java.library.path from Eclipse

JavaEclipseConfigurationBuildpath

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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

-Djava.library.path=blahblahblah...

Solution 3 - Java

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.

Solution 4 - Java

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.

Solution 5 - Java

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

Solution 6 - Java

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

Solution 7 - Java

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.

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

Solution 9 - Java

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

Solution 10 - Java

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

Solution 11 - Java

Remember to include the native library folder in PATH.

Solution 12 - Java

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

Solution 13 - Java

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.

Solution 14 - Java

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.

Solution 15 - Java

You can add vm argument in your Eclipse.

Example :

-Djava.ext.dirs=cots_lib

where cots_lib is your external folder library.

Solution 16 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJanuszView Question on Stackoverflow
Solution 1 - JavaJohn GardnerView Answer on Stackoverflow
Solution 2 - Javamatt bView Answer on Stackoverflow
Solution 3 - JavaschieferstapelView Answer on Stackoverflow
Solution 4 - JavaScott StanchfieldView Answer on Stackoverflow
Solution 5 - JavasonahtView Answer on Stackoverflow
Solution 6 - JavaMr LouView Answer on Stackoverflow
Solution 7 - Javauser825628View Answer on Stackoverflow
Solution 8 - JavaGünterView Answer on Stackoverflow
Solution 9 - JavajimView Answer on Stackoverflow
Solution 10 - JavaAurelienView Answer on Stackoverflow
Solution 11 - JavaJuanFran AdameView Answer on Stackoverflow
Solution 12 - JavaalexventuraioView Answer on Stackoverflow
Solution 13 - JavavardhamanView Answer on Stackoverflow
Solution 14 - JavamarcView Answer on Stackoverflow
Solution 15 - Javadella raharjoView Answer on Stackoverflow
Solution 16 - JavakhangulmalikView Answer on Stackoverflow