Reputation: 189444
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.
Upvotes: 217
Views: 457448
Reputation: 1063
Except the way described in the approved answer, there's another way if you have single native libs in your project.
java.library.path
.Upvotes: 24
Reputation: 189
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.
Upvotes: 5
Reputation: 1807
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"));
}
}
Upvotes: 6
Reputation: 425
You can add vm argument in your Eclipse.
Example :
-Djava.ext.dirs=cots_lib
where cots_lib
is your external folder library.
Upvotes: 0
Reputation: 25106
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.
Upvotes: 301
Reputation: 10054
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
Upvotes: 1
Reputation: 997
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.
Upvotes: 0
Reputation: 19
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
Upvotes: -1
Reputation: 25
Sometime we dont get Java Build Path by directly right click on project. then go to properties....
Then Click on java build path
Click on tab add external jars and give path of your computer file where u have stored jars.
Upvotes: 0
Reputation: 117
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.
Upvotes: 5
Reputation: 281
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
Upvotes: 3
Reputation: 1552
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...
Upvotes: 4
Reputation: 30634
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.
Upvotes: 12
Reputation: 139921
If you are adding it as a VM argument, make sure you prefix it with -D
:
-Djava.library.path=blahblahblah...
Upvotes: 39