File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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: 15082

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 8 API documentation
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

Perhaps can help you.

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:
subject: Why overwriting "java.library.path" doesn't work?
It's not a secret anymore!