views:

11311

answers:

7

Hi,

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)

A: 

Can you get round this by calling System.load() programmatically to load your native library? This method (unlike System.loadLibrary()) allows you to specify an absolute path.

Simon Nickerson
+4  A: 

SWT puts the necessary native DLLs into a JAR. Search for "org.eclipse.swt.win32.win32.x86_3.4.1.v3449c.jar" for an example.

The DLLs must be in the root of the JAR, the JAR must be signed and the DLL must appear with checksum in the META-INF/MANIFEST.MF for the VM to pick them up.

Aaron Digulla
How can I do it with NetBeans?
Maciek Sawicki
AFAIK, NetBeans uses Ant to build the project. Read the documentation for Ant how to create signed JARs and how to put things like DLLs into the manifest.
Aaron Digulla
A: 

Like this:

-Djava.library.path="C:/MyLibPath;%PATH%"

%PATH% is your old -Djava.library.path

andy boot
Tried this idea but it resulted as java.library.path : D:\Workspace\myProject\lib;%PATH%
Touko
A: 

In UNIX systems, you can append to the LD_LIBRARY_PATH environment variable. On Windows, the JVM automatically sets the system property, java.library.path, to PATH; so if the dll is on your PATH, then you're set.

geowa4
A: 

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.

Fabian Steeg
-1. You're assuming the end-user is running the application from an IDE, which is unlikely.
finnw
@finnw I see your point. I found the question looking for a solution on how to add a native library in the IDE during development, without overriding `java.library.path` and came back after finding the solution elsewhere. Will edit my answer to make that clearer.
Fabian Steeg
Actually I'm working with Eclipse even though I didn't mention it at the question.
Touko
+2  A: 

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.

Touko
A: 

The native library file name has to correspond to the Jar file name. This is very very important. Please make sure that jar name and dll name are same. Also,please see the post from Fabian Steeg My download for jawin was containing different names for dll and jar. It was jawin.jar and jawin*d*.dll, note extra 'd' in dll file name. I simply renamed it to jawin.dll and set it as a native library in eclipse as mentioned in post "http://www.eclipsezone.com/eclipse/forums/t49342.html"

Dhana