Skip to main content

Running a jar file without the -Djava.library.path instruction

7 replies [Last post]
tuxtlequino
Offline
Joined: 2006-03-28
Points: 0

Ok, my application is running, but not as I would like it to run. I still need to use the -Djava.library.path instruction or I get the error:

java.lang.UnsatisfiedLinkError: no jdic in java.library.path

I want to know if it is possible to run my jar without that instruction. I would make it much easier to run. The jdic has it own folder (/org/jdesktop/jdic/) inside the jar. I have tried a lot of things, but nothing seems to work.

I want to bo able to run everything from as single jar. Anybody has any idea?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tuxtlequino
Offline
Joined: 2006-03-28
Points: 0

Thank you guys!. Now I am running with other problems, but I think that is a topic for another post :D.

michael_shan
Offline
Joined: 2005-05-29
Points: 0

Hi,

A single jdic.jar in classpath is engough. Put jdic.dll or libjdic.so under the same folder with jdic.jar (for win/linux/solairs etc., not for the cross platform build), the jar will set the java.library.path automatically. You can see that samples of jdic run normally without setting the library path.

gdavison
Offline
Joined: 2004-03-30
Points: 0

Hi,

Out of interest how does jdic do this? I tried to look at the JDIC site; but it seems to be down at the moment.

Gerard

nicity
Offline
Joined: 2006-01-16
Points: 0

Sets java.library.path programmatically relative to jdic.jar

gdavison
Offline
Joined: 2004-03-30
Points: 0

Hmm,

Actually it is not quite that simple, as it appears from the source code that jdic needs to reset a static field on ClassLoader to null in order for this to work as that property is supposed to be only read once:

// Add the binary path (including jdic.dll or libjdic.so) to
// "java.library.path", since we need to use the native methods in
// class InitUtility.
String newLibPath = binaryPath + File.pathSeparator +
System.getProperty("java.library.path");
System.setProperty("java.library.path", newLibPath);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
if (fieldSysPath != null) {
fieldSysPath.set(System.class.getClassLoader(), null);
}

Not sure this is a good idea; but it seem to work for them

Gerard

nicity
Offline
Joined: 2006-01-16
Points: 0

This stuff is just to reset caches of library pathes in ClassLoader

michael_shan
Offline
Joined: 2005-05-29
Points: 0

ClassLoader will load libraries from sys_path if it's not null,so we have to set the sys_path to null and let it search in the "java.library.path".