0

How to add java.library.path at run time i have tried below but it seems like not working, I also tried option 2 from post but this too not working ;(

// define the var
var path = System.getProperty("java.library.path");
var os = NativeSystem.getFamily().toString().toLowerCase();
var arch = NativeSystem.getArchitecture().toString().toLowerCase();
var libPath = System.getProperty("java.home");

// create path
libPath = libPath.trim() + File.separator + os + File.separator + arch;

// set path
System.setProperty("java.library.path", path + libPath);

There is any way to do it ?

srilakshmikanthanp
  • 2,008
  • 1
  • 6
  • 19
  • 1
    I don't think it's possible in later versions of Java. – Rubydesic Jan 27 '22 at 07:03
  • 1
    If you want to load a library at runtime (which I assume is what you actually want to do) have a look at `System.load()` or `System.loadLibrary()`. – Thomas Jan 27 '22 at 07:06
  • I am using external library [jnativehook](https://github.com/kwhat/jnativehook) i need to set path to load dill files for more info please have a look at [issue](https://github.com/kwhat/jnativehook/issues/394) – srilakshmikanthanp Jan 27 '22 at 07:08
  • 1
    Can you specify what's not working? Is it the property that doesn't get changed or does the library you're using not pick it up correctly? In the latter case you should refer to that lib's docs or get in touch with the dev. But before that you might want to look at the path you're setting: `path + libPath` looks like it's missing a separator between multiple paths (`;` or `:` depending on the OS). – Thomas Jan 27 '22 at 07:16
  • Results is error java.lang.UnsatisfiedLinkError: URI scheme is not "file" with javafx:jlink and i manually copied the dill to the image location – srilakshmikanthanp Jan 27 '22 at 07:19
  • It is easy to handle `System.loadLibrary` yourself for any new path not defined in "java.library.path". However the exception you report in comments above was not thrown by `System.load` / `System.loadLibrary`, but was thrown by jnativehook after interpretting "javafx:jlink" as library name. So your question looks to be about using jnativehook with Maven - and needs editing to reflect that. – DuncG Jan 27 '22 at 13:38
  • Thanks for youe replay i fixed it with system.load see the [issus](https://github.com/kwhat/jnativehook/issues/394) for more info – srilakshmikanthanp Jan 27 '22 at 17:19

0 Answers0