To load dynamically a jar to classpath I used to use the following code with Java 8.
File file = new File(jarPath);
URL u = f.toURI().toURL();
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(urlClassLoader, new Object[]{u});
However using Java 11 does not work anymore. I have tried some solution provided in the internet but none of them works for me.
Please could you help me to resolve this problem.
Thanks