2011-12-12 50 views
0

我的項目運行具有以下命令完美的罰款:如何通過maven執行簡單的螞蟻通話?

C:\project\<project_name>\ant -lib ant\lib -buildfile applications/<sub-project-path>/ant/build.xml deploy 

但是,如果我在POM包裝這個命令無論是在Maven的antrun-插件或者exec-Maven的插件,我得到的各種路徑的問題。

對於maven-antrun-plugin,似乎某些屬性由於路徑問題而無法加載。在exec-maven-plugin中,似乎螞蟻目標從未正確傳入。
有人可以請教如何我可以應用這在一個POM文件?非常感激。

這是我的exec POM:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.2.1</version> 
      <executions> 
       <execution> 
        <phase>process-resources</phase> 
        <goals> 
         <goal>exec</goal> 
        </goals> 
        <configuration> 
        <executable>ant</executable> 
        <workingDirectory>${basedir}</workingDirectory> 
        <arguments> 
         <argument>'-lib ant/lib'</argument> 
         <argument>'-buildfile $basedir/<project-path>/build.xml'</argument> 
         <argument>deploy</argument> 
        </arguments> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
+0

好的,我已經找到了這裏的問題。顯然在爭論中,你不能傳遞空間。所以這個問題解決了。不過,我仍然很好奇如何在antrun-plugin中寫這個。這是pom文件,它不知道如何解析路徑。 –

回答

0

你應該通過所需的依賴直接進入antrun插件聲明,之後<executions>元素。

<plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <version>1.2.1</version> 
     <executions> 
      ... 
     </executions> 
     <dependencies> 
      <dependency> 
      <groupId>ant-contrib</groupId> 
      <artifactId>ant-contrib</artifactId> 
      <version>${ant-contrib.version}</version> 
      <exclusions> 
       <exclusion> 
       <groupId>ant</groupId> 
       <artifactId>ant</artifactId> 
       </exclusion> 
      </exclusions> 
      </dependency> 
      <dependency> 
      <groupId>org.apache.tomcat</groupId> 
      <artifactId>jasper</artifactId> 
      <version>${tomcat.compile.version}</version> 
      </dependency> 
      <dependency> 
      <groupId>com.sun</groupId> 
      <artifactId>tools</artifactId> 
      <version>${java.version}.0</version> 
      <scope>system</scope> 
      <systemPath>${jdk.home}/tools.jar</systemPath> 
      </dependency> 
     </dependencies> 
    </plugin> 

我已經在我們的項目中使用了一些庫,以便您舉個例子。請注意,如果您的構建使用了一些非標準(即java.lang以外的Java API類),則必須通過tools.jar作爲依賴關係。

另外,如果你使用ant-contrib不要忘記排除ant作爲依賴,因爲它依賴於一些古老的螞蟻版本,你會得到一個版本衝突。

另一個煩人的事情是,直接分配給插件執行的依賴不屬於POM的<dependencyManagement>,所以你必須拼出精確的版本。一種解決方法是在與中心<dependencyManagement>相同的位置聲明版本屬性,並使用屬性而不是硬編碼版本。

1

還沒有嘗試過,但你可以做一些類似於maven antrun插件example中記錄的內容。

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <version>1.7</version> 
     <executions> 
      <execution> 
      <id>ant</id> 
      <phase>process-resources</phase> 
      <configuration> 
       <target> 
       <ant antfile="${basedir}/<project-path>/build.xml"> 
        <target name="deploy"/> 
       </ant> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 

不知道你想傳遞作爲參數在上面的代碼片段-lib什麼庫,但同樣可以聲明爲plugindependencies

請注意,這個插件並不關心繫統中是否存在ant安裝。它下載必要的ant庫。