title: Add jar to classpath at runtime under java 9
body: <p>Until <a href="/questions/tagged/java9" class="post-tag" title="show questions tagged &#39;java9&#39;" rel="tag">java9</a> for adding external jar to classpath in runtime by programmatically everybody used:</p>
  
  <pre><code>URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
  Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
  method.invoke(sysloader, new Object[]{file.toURI().toURL()});
  </code></pre>
  
  <p>Now with java9 we have problem:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ClassCastException:
        java.base/jdk.internal.loader.ClassLoaders$AppClassLoader
        cannot be cast to java.base/java.net.URLClassLoader</p>
  </blockquote>
  
  <p><code>URLClassLoader</code> doesn't work anymore in Java 9. What to do now under jdk9 for adding an external jar to the classpath in runtime programmatically?</p>