2011-10-13 85 views

回答

6

你可以在Maven AntRun Plugin的幫助下做到這一點。

在樣本Ant腳本執行上乾淨相和Ant-Contrib library使用:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <version>1.6</version> 
      <executions> 
       <execution> 
        <phase>clean</phase> 
        <configuration> 
         <tasks> 
          <taskdef resource="net/sf/antcontrib/antcontrib.properties" /> 

          <if> 
           <available file="d:\file_to_check.txt"/> 
           <then> 
            <echo>The file exists</echo> 
           </then> 

           <else> 
            <echo>The file does not exist</echo> 
           </else> 
          </if> 
         </tasks> 
        </configuration> 
        <goals> 
         <goal>run</goal> 
        </goals> 
       </execution> 
      </executions> 
      <dependencies> 
       <dependency> 
        <groupId>ant-contrib</groupId> 
        <artifactId>ant-contrib</artifactId> 
        <version>20020829</version> 
       </dependency> 
      </dependencies> 
     </plugin> 
    </plugins> 
</build> 

您還可以查看此鏈接:How to execute tasks conditionally using the maven-antrun-plugin?