Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何加载jar类,就像它们被库引用一样?_Java_Classloader_Runtimeexception - Fatal编程技术网

Java 如何加载jar类,就像它们被库引用一样?

Java 如何加载jar类,就像它们被库引用一样?,java,classloader,runtimeexception,Java,Classloader,Runtimeexception,我在jar类中加载了: ClassLoader.getSystemClassLoader().loadClass(name) 在我的插件加载程序中。但JVM似乎没有将它们注册为类,就好像它们被引用一样,因此它们会被垃圾回收,我得到: 运行时ClassNotFoundException 如何将它们注册为引用库? 另外,JVM如何加载引用的库类并在JVM生命周期内保持它们的注册?我们可以这样注册运行时加载的类吗 例如: 在我的主项目中有一个名为AbstractAction的抽象类。然后一个jar调

我在jar类中加载了:

ClassLoader.getSystemClassLoader().loadClass(name)
在我的插件加载程序中。但JVM似乎没有将它们注册为类,就好像它们被引用一样,因此它们会被垃圾回收,我得到:

运行时ClassNotFoundException

如何将它们注册为引用库? 另外,JVM如何加载引用的库类并在JVM生命周期内保持它们的注册?我们可以这样注册运行时加载的类吗

例如:


在我的主项目中有一个名为AbstractAction的抽象类。然后一个jar调用x.jar在ActionImpl中实现它。我在运行时加载jar并使用ActionImpl。但是像ActionImpl一样的UTIL中使用的类没有加载,我在UTIL上得到ClassNotFoundException。

那么“UTIL”在哪里?它在类路径上吗?当然在jar中。我还使用类加载器加载了Utils,但仍然存在相同的错误。