2012-10-30 98 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