Loading a class using the URLClassLoader
Posted by zone817The URLClassLoader can be used dynamically load classes from a directory , not necessarily on the classpath. The following code demonstrates how
File file = new File("<directory path>"); try { URL url = file.toURL(); ClassLoader loader= new URLClassLoader(new URL[]{url}); Class class= loader.loadClass("<class name>"); } catch (MalformedURLException e) { } catch (ClassNotFoundException e) { }
0 comments:
Post a Comment