我有一个加载类的自定义插件,例如
Class<?> clazz = Class.forName(NAME_OF_CLASS_FROM_HOST_DEPENDENCIES);
NAME_OF_CLASS_FROM_HOST_DEPENDENCIES - 是项目依赖项中存在的类,使用此插件。
在托管项目pom中,我调用这样的插件:
<plugin>
<groupId>com.plugins</groupId>
<artifactId>the_plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>do</id>
<phase>process-classes</phase>
<goals>
<goal>do</goal>
</goals>
</execution>
</executions>
</plugin>
获取ClassNotFoundException
重要的是,这些依赖关系在pom中定义为
<scope>provided</scope>
答案 0 :(得分:0)
结束以下。
List<URL> listUrl = new ArrayList<URL>();
Set<Artifact> deps = project.getDependencyArtifacts();
for (Artifact artifact : deps) {
final URL url = artifact.getFile().toURI().toURL();
listUrl.add(url);
}
newClassLoader = new URLClassLoader(listUrl.toArray(new URL[listUrl.size()]), Thread.currentThread().getContextClassLoader());