美文网首页
java url类加载器

java url类加载器

作者: simplerandom | 来源:发表于2020-06-28 10:54 被阅读0次
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();
    }
}

相关文章

网友评论

      本文标题:java url类加载器

      本文链接:https://www.haomeiwen.com/subject/yypifktx.html