2012-10-30 122 views
1

我的應用程序依賴於第三方耳朵(它解構它,添加/修改其中的某些項目,並將其重構爲新耳朵)。第三方耳朵必須使用第三方構建腳本構建。使用外部構建腳本的maven

我想學習「maven-y」方法來設置它。我希望我需要將第三方的耳朵安裝到我的倉庫中。

我想爲第三方耳朵創建一個pom.xml,它將構建第三方耳朵並安裝/部署它。我創建了一個pom.xml,它可以成功地調用第三方構建腳本(通過maven-antrun-plugin),並在默認的Maven Ear項目中創建耳朵。

我的問題是,maven的安裝插件失敗,因爲它無法找到存檔(它期望任何插件包裝有工件對象上設置一個屬性,而maven-antrun-plugin不這樣做)。

mvn package工作正常,並生成耳朵。

確切的錯誤信息運行mvn install時看起來是這樣的:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install (default-install) on project third_party_ear: The 
packaging for this project did not assign a file to the build artifact -> [Help 1] 

有沒有一種更好的方式去這件事嗎?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.thirdparty</groupId> 
    <artifactId>third_party_ear</artifactId> 
    <version>9.0</version> 
    <packaging>ear</packaging> 

    <name>third_party_ear</name> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-ear-plugin</artifactId> 
       <version>2.6</version> 
       <executions> 
        <execution> 
         <id>default-ear</id> 
         <phase>none</phase> 
        </execution> 
        <execution> 
         <id>default-generate-application-xml</id> 
         <phase>none</phase> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.7</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <configuration> 
          <target> 
           <subant target="build-ear" antfile="build.xml" buildpath="${project.basedir}"/> 
          </target> 
         </configuration> 
         <goals> 
          <goal>run</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

回答

2

當您指定<packaging>ear</packaging>時,您告訴Maven調用爲該包裝指定的完整生命週期。

在你的情況,你想做的事就是寫一個包裝pom.xml,只是彈了你的第三方構建腳本,而不必調用EAR生命週期和產生的神器重視Maven的反應器...

像這樣的東西應該工作

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.thirdparty</groupId> 
    <artifactId>third_party_ear</artifactId> 
    <version>9.0</version> 
    <packaging>pom</packaging> 

    <name>third_party_ear</name> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.7</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <configuration> 
          <target> 
           <subant target="build-ear" antfile="build.xml" buildpath="${project.basedir}"/> 
           <attachartifact file="${project.build.directory}/${project.build.finalName}.ear" type="ear"/> 
          </target> 
         </configuration> 
         <goals> 
          <goal>run</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

可能有一些輕微的毛刺,因爲POM的包裝不同......但因爲這不是一個classpath相關神器,他們不應該影響到你。

注意attachartifact ANT任務可以在任何地方附加一個神器,所以你不需要與ANT爭鬥以將文件放在「正確的」位置......儘管遵循該慣例更好。您可能不想使用project.build.finalName並對文件名進行硬編碼。

+0

這看起來完成了工作。 pom似乎是我失蹤。感謝上帝爲maven mavens。感謝您的及時答覆。 – Warren