尝试创建一个类的对象,其绝对路径仅已知

huangapple 未分类评论45阅读模式
英文:

Trying to make the object of a class, whose absolute path is known only

问题

File fi = new File("file:///home/abc/Desktop/test/out/production/test/");

URL url = fi.toURI().toURL();
URL[] urls = new URL[]{url};

URLClassLoader classLoad = new URLClassLoader(urls);
Class<?> v = classLoad.loadClass("test.out.production.test.Rout");

// Absolute Path of the class whose object should be created /home/abc/Desktop/test/out/production/test/Rout  (Rout is the required class)

// But it is giving ClassNotFound Exception.
英文:
        File fi = new File(&quot;file:///home/abc/Desktop/test/out/production/test/&quot;);

        URL url = fi.toURI().toURL();       
        URL[] urls = new URL[]{url};

        URLClassLoader classLoad = new URLClassLoader(urls);
        Class&lt;?&gt; v = classLoad.loadClass(&quot;test.out.production.test.Rout&quot;);

Absolute Path of the class whose object should be created /home/abc/Desktop/test/out/production/test/Rout (Rout is the required class)

But it is giving ClassNotFound Exception.

huangapple
  • 本文由 发表于 2020年6月29日 17:16:28
  • 转载请务必保留本文链接:https://java.coder-hub.com/62634942.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定