package hello;
public class Hello {
String name;
public Hello(String name) {
this.name = name;
}
public Hello() {
System.out.println("hello对象");
}
}
public class Demo {
public static void main(String[] args)
throws MalformedURLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
File file = new File("C:\\MyApplication\\idea\\jmx\\target\\classes");
URI uri = file.toURI();
URL url = uri.toURL();
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {url});
System.out.println(urlClassLoader.getParent());
Class<?> aClass = urlClassLoader.loadClass("hello.Hello");
aClass.newInstance();
}
}
网友评论