Adding new paths for native libraries at runtime in Java9

I have an application that contains some native code. To make it easier for users to install and run, I extended the ClassLoader.sys_paths private field at runtime, as described in this previous question: Adding new paths for native libraries at runtime in Java . With this hack, the application can work with a simple unvarnished command java -jar app.jar, and its own objects will be correctly located in the installation directory.

This method no longer works in Java 9 (see How to solve the InaccessibleObjectException ("Cannot make {member} accessible: module {A} does not open {package} on {B}") on Java 9? ). This article describes the changes in Java 9 and proposes a solution (adding arguments to the command line to open the module), but it prejudices my original intention to allow simple java command execution.

Is there a way to change the search path of the source library at runtime, or is it considered too much loaded gun to leave it?

+4
source share

Source: https://habr.com/ru/post/1678131/


All Articles