1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
String jar = "monjar.jar" ;
URLClassLoader ucl = (URLClassLoader) ClassLoader.getSystemClassLoader() ;
Class<?> sysclass = URLClassLoader.class;
try {
Method method = sysclass.getDeclaredMethod("addURL", new Class<?>[]{URL.class}) ;
method.setAccessible(true) ;
method.invoke(ucl, new Object[]{new URL("jar", "", jar)}) ;
}
catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
{
e.printStackTrace() ;
System.err.println("Error, could not add URL to system class loader") ;
System.exit(-1) ;
} |