2017-04-08 5 views
0

クラスを読み込むカスタムプラグインがあります。プロジェクトをホスティングしてクラスを読み込むためのMaven mojoプラグイン

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

の取得、

<scope>provided</scope> 

答えて

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()); 
関連する問題