Java Maven mojo插件从托管项目加载类

Java Maven mojo插件从托管项目加载类,java,maven,maven-plugin,Java,Maven,Maven Plugin,我有一个加载类的自定义插件,例如 Class<?> clazz = Class.forName(NAME_OF_CLASS_FROM_HOST_DEPENDENCIES); Class clazz=Class.forName(来自主机依赖项的类的名称); NAME_OF_CLASS_FROM_HOST_DEPENDENCIES-是存在于使用此插件的项目依赖项中的类 在主持项目pom时,我将插件称为: <plugin> <groupId>com.plug

我有一个加载类的自定义插件,例如

Class<?> clazz = Class.forName(NAME_OF_CLASS_FROM_HOST_DEPENDENCIES);
Class clazz=Class.forName(来自主机依赖项的类的名称);
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>

com.plugins
_插件
1.0-快照
做
进程类
做
获取ClassNotFoundException

重要的是,pom中定义的依赖项

<scope>provided</scope>
已提供

以以下内容结束

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());
List listUrl=new ArrayList();
Set deps=project.getDependencyArtifacts();
用于(工件工件:deps){
最终URL=artifact.getFile().toURI().toURL();
添加(url);
}
newClassLoader=newUrlClassLoader(listUrl.toArray(newURL[listUrl.size()]),Thread.currentThread().getContextClassLoader());

以以下内容结束

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());
List listUrl=new ArrayList();
Set deps=project.getDependencyArtifacts();
用于(工件工件:deps){
最终URL=artifact.getFile().toURI().toURL();
添加(url);
}
newClassLoader=newUrlClassLoader(listUrl.toArray(newURL[listUrl.size()]),Thread.currentThread().getContextClassLoader());