我有以下代码片段
URL url = new File("c:/work/projects/jars/").toURI().toURL();
URL[] urls = new URL[]{url};
URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());
URL res = child.findResource("temp.txt");
cls = child.loadClass("com.foo.adapter.sample.PluginImpl");jars文件夹包含一个文本文件"temp.txt“和一个包含PluginImpl类的jar文件。资源已加载,但类未加载。当我将jar的内容解压缩到文件夹中时,类就被加载了。我哪里错了?
发布于 2011-07-10 01:37:59
您必须将JAR本身添加到类路径中。JVM区分了资源、和JAR。这应该是可行的:
URL url1 = new File("c:/work/projects/jars/").toURI().toURL(); // resources
URL url2 = new File("c:/work/projects/jars/myjar.jar").toURI().toURL(); // jar
URL[] urls = new URL[]{url1, url2};https://stackoverflow.com/questions/6636326
复制相似问题