I have the following legacy code that I migrated to Java 16 but, due to the strong encapsulation introduced by this new version, it doesn't work:
try {
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke(new URLClassLoader(
new URL[] {}),
new File("C:/external-folder/my.jar").toURI().toURL()
);
} catch (Exception exc) {
exc.printStackTrace();
}
Is there a way to make it work?
See Question&Answers more detail:os