aspose file tools*
The moose likes Java in General and the fly likes Why overwriting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why overwriting "java.library.path" doesn Watch "Why overwriting "java.library.path" doesn New topic
Author

Why overwriting "java.library.path" doesn't work?

D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

My code dynamically resolves native libraries location, however I can't use System.load("complete path") because the libraries are loaded in 3rd party Java code. So if I even preload libraries, 3rd party code fails with
unsatisfied link error.
An attempt to overwrite "java.library.path" doesn't work either.

I looked in System.setProperty and java.lang.ClassLoader.loadLibrary source and didn't find an answer. Yes, after every reload properties, class System does native call to initialize default values, however it doesn't happen for setProperty call. loadLibrary doesn't do any magic either, it does read property from System and trying to locate native libraries. So where is the magic? I do not want to debug java.lang package, hoping that somebody knows a solution here.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14157
    
  19

Specify it on the command line with the -D option when you run your Java program:

java -Djava.library.path=<path to DLL dir> com.mypackage.MyMainClass


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Perhaps java.net.URLClassLoader can help you.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by D Rog:
So if I even preload libraries, 3rd party code fails with
unsatisfied link error.


If you are loading your native libraries via native code, you can register the functions that support Java native methods using JNI RegisterNatives() function.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why overwriting "java.library.path" doesn't work?