Created
May 3, 2010 11:01
-
-
Save mvuksano/387972 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Dynamically add folder to class search path (so called classpath). | |
| */ | |
| package com.google.gwt.dist.util; | |
| import java.io.File; | |
| import java.lang.reflect.InvocationTargetException; | |
| import java.lang.reflect.Method; | |
| import java.net.MalformedURLException; | |
| import java.net.URL; | |
| import java.net.URLClassLoader; | |
| import java.util.logging.Level; | |
| import java.util.logging.Logger; | |
| public class Util { | |
| @SuppressWarnings("unchecked") | |
| private static final Class[] parameters = new Class[] { URL.class }; | |
| private static final Logger logger = Logger.getLogger(Util.class.getName()); | |
| /** | |
| * This method adds a folder to class search path at runtime. | |
| * | |
| * @param u | |
| * URL of the folder to be added to class search path. | |
| */ | |
| public static void addUrl(URL u) { | |
| URLClassLoader sysloader = (URLClassLoader) ClassLoader | |
| .getSystemClassLoader(); | |
| Class<URLClassLoader> sysclass = URLClassLoader.class; | |
| try { | |
| Method method = sysclass.getDeclaredMethod("addURL", parameters); | |
| method.setAccessible(true); | |
| method.invoke(sysloader, new Object[] { u }); | |
| } catch (NoSuchMethodException e) { | |
| logger.log(Level.SEVERE, e.getMessage()); | |
| } catch (InvocationTargetException e) { | |
| logger.log(Level.SEVERE, e.getMessage()); | |
| } catch (IllegalAccessException e) { | |
| logger.log(Level.SEVERE, e.getMessage()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment