2012-03-31 116 views
3

我需要以某种方式找到maven的类路径,即所有依赖关系等等,并将其用作插件配置的一部分。下面是一个示例从配置中检索Maven类路径

...<systemProperties> 
     <systemProperty> 
      <name>some.system.property.here</name> 
      <value>${maven.runtime.classpath}</value> 
     </systemProperty> 
    </systemProperties> 
    </configuration>... 

不幸的是,$ {maven.runtime.classpath}是空的。有什么与此相同的吗?

回答

2

做的最简单的办法是使用像Groovy和设置它编程。

这是需要包含的配置。

 <plugin> 
      <groupId>org.codehaus.gmaven</groupId> 
      <artifactId>gmaven-plugin</artifactId> 

      <configuration> 
       <source> 
        import org.codehaus.plexus.util.StringUtils; 
        import java.io.File; 

        System.setProperty("your.classpath.property", StringUtils.join(project.getRuntimeClasspathElements().iterator(), File.pathSeparator)); 
       </source> 
      </configuration> 

      <executions> 
       <execution> 
        <phase>generate-sources</phase> 

        <goals> 
         <goal>execute</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin>