Guest User

Untitled

a guest
Nov 12th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. public class CPath {
  2.     private static final Class[] parameters = new Class[] {URL.class};
  3.  
  4.     public static void addFile(String s) throws IOException
  5.     {
  6.         File f = new File(s);
  7.         addFile(f);
  8.     }
  9.  
  10.     public static void addFile(File f) throws IOException
  11.     {
  12.         addURL(f.toURI().toURL());
  13.     }
  14.  
  15.     public static void addURL(URL u) throws IOException
  16.     {
  17.         URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
  18.         Class sysclass = URLClassLoader.class;
  19.  
  20.         try {
  21.             Method method = sysclass.getDeclaredMethod("addURL", parameters);
  22.             method.setAccessible(true);
  23.             method.invoke(sysloader, new Object[] {u});
  24.         } catch (Throwable t) {
  25.             t.printStackTrace();
  26.             throw new IOException("Error, could not add URL to system classloader");
  27.         }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment