2012-03-31 180 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>