Java reflections gives us the ability to load a class, but using simple class loaders you can load a class which is there in classpath. But how to load the class which is not there in classpath?
Well, its not that hard.
URLClassLoader is there for us. Look at following code, which shows how to use URLClassLoader.
Well, its not that hard.
URLClassLoader is there for us. Look at following code, which shows how to use URLClassLoader.
File file=new File("path to you directory in which your class is"); URL urls[]={ file.toURI().toURL() }; URLClassLoader loader=new URLClassLoader(urls); Class object=loader.loadClass("classname");
Comments
Post a Comment