views:

18104

answers:

4

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.

+4  A: 

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

-Djava.library.path=blahblahblah...
matt b
+1  A: 

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

jim
Also - in the run configuration, go to the "Common" tab and choose a place in your project to save the run config. This allows you to check in that run configuration (xxxx.launch file) so that others on your team can reuse it.
Scott Stanchfield
+23  A: 

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.

Specificly: 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 screw up something that is already properly set by eclipse.

John Gardner
OK this seems to work. Now the right path is actual shown in the error message. required library not found : /Users/janusz/Documents/workspace/SlideSelector/lib/libOpenCV.jnilib. The file is in exactly this directory. Seems to be another error
Janusz
But how does this work if you have more than one folder to add?
Dan
that's a good question. Why do you have more than one folder of native libraries for one jar? I'm pretty sure there is a way where you can embed the native libraries themselves into the jar, so that might be the way to go?
John Gardner
I'm working on a legacy project over which I have very little control. I certainly can't change the project structure. My workaround for the moment is to put everything on my PATH - but that's not so nice.
Dan
depending on OS, you could create one directory that is all symbolic links to the other libraries? or at least for development purposes you could copy all the libs to one directory.
John Gardner
+5  A: 

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.

Scott Stanchfield