Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps java.net.URLClassLoader can help you.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic