Search code examples
javadynamic-class-loaders

How to use Oracle documentation for constructing URI


I went through URL API on Oracle documentation. I want to construct URI to refer Jars located on remote machine but, from the specs I am not able to make out how to use them. The document gives reference to RFC2396 for specs. but, that too doesn't provide any concrete examples for its usage.


Solution

  • Following code is useful for jar loading

    Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
    method.setAccessible(true);
    method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{new URL("http://somewhere.net/library.jar")});  
    Class.forName("your.remote.ClassName");