• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps java.net.URLClassLoader can help you.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic