替换默认的Maven生命周期目标

时间:2011-06-29 09:49:42

标签: java tomcat maven-2

当我在项目mvn deploy中运行<packaging>war</packaging>时出现错误:

  

[错误]无法在项目store-service-impl上执行目标org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy(default-deploy):部署失败:未在POM内部的distributionManagement元素或-DaltDeploymentRepository = id :: layout :: url参数

默认情况下,deploy:deploy目标似乎与deploy生命周期阶段绑定。换句话说,当运行deploy生命周期阶段时,Maven将尝试将生成的artefact(在这种情况下为.war文件)部署到远程存储库。

就我而言,我想将war部署到远程Tomcat实例而不是远程Maven存储库。我已将以下内容添加到pom.xml

       <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.1.1</version>
            <configuration>
                <container>
                    <containerId>tomcat6x</containerId>
                    <type>remote</type>
                </container>
                <!--
                <executions>
                    <execution>
                        <id>deploy-tomcat</id>
                        <phase>deploy</phase>
                        <goals>
                           <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
                -->
                <configuration>
                    <type>runtime</type>
                    <properties>
                        <cargo.remote.uri>http://10.60.60.60:8080/manager</cargo.remote.uri>
                        <cargo.remote.username>jack</cargo.remote.username>
                        <cargo.remote.password>secret</cargo.remote.password>
                    </properties>
                </configuration>
                <deployer>
                    <type>remote</type>
                </deployer>
            </configuration>
        </plugin>

当我运行mvn cargo:deploy时,这会成功部署.war。但是,如果我通过取消注释deploy元素将此目标绑定到Maven生命周期的<executions>阶段,则会出现上述错误。

似乎已将cargo:deploy目标添加到与deploy阶段绑定的目标中,但我希望替换 deploy:deploy目标与deploy目标绑定到cargo:deploy生命周期阶段(默认情况下),这可能吗?

3 个答案:

答案 0 :(得分:2)

您应该将货物绑定到pre-integration-test而不是deploy - 然后您的故障安全测试可以在integration-test阶段针对部署的war文件运行。您可以使用mvn verify运行测试。

答案 1 :(得分:2)

您可以在配置货物之前尝试禁用部署插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

答案 2 :(得分:1)

您可以在执行ID default-deploy上使用maven-deploy-plugin禁用默认部署目标。老线程,我把它放在这里以防万一。

<plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.7</version>
    <executions>
        <execution>
            <id>default-deploy</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>