1

I was trying to automatically set the native library path and the JAR's path automatically during the runtime of a program of mine (in other words, I would like to perform the settings' definition through code.

I tried to execute the following in the beginning of my program flow:

System.setProperty("java.library.path", "\\some_folder");

apparently this should set up the native library path, but the application could not load the dlls in the folder. I've also tried some variations (like "jni.library.path") but none of them seemed to work. Is there another way to solve this?

Mudkip
  • 373
  • 6
  • 27
  • I could find a solution regarding the native path in this link: http://stackoverflow.com/questions/15409223/adding-new-paths-for-native-libraries-at-runtime-in-java But there is still the JAR adding issue (through code)... should it be a similar approach? – Mudkip May 15 '14 at 07:43

1 Answers1

1

The java.library.path is read only once when the JVM starts up. If you change this property using System.setProperty, it won't make any difference. the following blog provides options to load dlls in runtime. http://fahdshariff.blogspot.jp/2011/08/changing-java-library-path-at-runtime.html

  • create a new URLClassLoader (or a custom subclass) with the new URL in the constructor arguments. Use that loader to load some anchor for your app, and anything from there down (if you do nothing else to break the chain) will have the same classpath. – user3636135 May 15 '14 at 07:56