Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add native library to "java.library.path" with Eclipse launch (instead of overriding it)

I got a native library that needs to be added to java.library.path. With JVM argument -Djava.library.path=path... I can set the path as I want.

My problem is that my other library (pentaho reporting) searches fonts based on the default java.library.path (including system directories etc) and the manual setting overrides the default path..

So : how can I add a path entry to the default java.library.path instead of overriding it (which seems to be done with -Djava.library.path)? (I wouldn't want to add the default path by hand, which wouldn't be nice for the sake of deployment)

EDIT: Sorry for missing details; I'm working with Eclipse. (The deployment is done with JNLP and there I can use nativelib under resources)

like image 579
Touko Avatar asked Mar 19 '09 07:03

Touko


People also ask

What is Native library location in eclipse?

Go to Project properties->Java Build Path->Source. You'll find a list of source-folders. Each entry under the the Source tab has Native library locations. It supports paths within the workspace and it will make Eclipse add it to your java.

What is the default Java library PATH?

Its default value depends on the operating system: On Windows, it maps to PATH. On Linux, it maps to LD_LIBRARY_PATH. On OS X, it maps to DYLD_LIBRARY_PATH.

Where is Java native library?

LIB/MYLIB. LIB is the path that contains the native library you want to load using the System. loadLibrary() call, and myclass is the name of your Java application. For information about how a native library is located by the System.


2 Answers

Had forgotten this issue... I was actually asking with Eclipse, sorry for not stating that originally. And the answer seems to be too simple (at least with 3.5; probably with older versions also):

Java run configuration's Arguments : VM arguments:

-Djava.library.path="${workspace_loc:project}\lib;${env_var:PATH}" 

Must not forget the quotation marks, otherwise there are problems with spaces in PATH.

like image 120
Touko Avatar answered Oct 02 '22 10:10

Touko


If you want to add a native library without interfering with java.library.path at development time in Eclipse (to avoid including absolute paths and having to add parameters to your launch configuration), you can supply the path to the native libraries location for each Jar in the Java Build Path dialog under Native library location. Note that the native library file name has to correspond to the Jar file name. See also this detailed description.

like image 44
Fabian Steeg Avatar answered Oct 02 '22 11:10

Fabian Steeg