Java Class.forName() from distant directory

前端 未结 3 1796
夕颜
夕颜 2020-12-01 22:29

I am currently loading Java classes using Class.forName() to load it.

clazz = Class.forName(\"interfaces.MyClass\");

But now I

3条回答
  •  误落风尘
    2020-12-01 22:55

    Use an URLClassLoader for this. The code might be something along the lines of:

    File f = new File("C:/dir");
    URL[] cp = {f.toURI().toURL()};
    URLClassLoader urlcl = new URLClassLoader(cp);
    Class clazz = urlcl.loadClass("distantinterfaces.DistantClass");
    

提交回复
热议问题