JNI dependent libraries

后端 未结 6 537
小鲜肉
小鲜肉 2020-12-31 03:52

I\'m running a library via JNI (I didn\'t write it), and internally it calls another DLL. I get an error saying \"Can\'t find dependent libraries\" unless I put the path of

6条回答
  •  生来不讨喜
    2020-12-31 04:03

    I've successfully injected a folder into the PATH variable using JNA. This can be used as a workaround if you want to deploy your dependent DLLs alongside your application without tainting the global environment or messing with explicit DLL load order.

    However it's not clear to me how the classloader lifecycle affects this. I've only tried this technique under the NetBeans module system, but if you look through the ClassLoader class code for loadLibrary, you'll see that it caches some path variables. It may or may not be necessary to create a new classloader to load the library on.

    The downside is you need to use JNA or JNI. Also, it seems like a pretty gross hack. See here for an example of how to set an environment variable using JNA.

提交回复
热议问题