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

Dón*_*nal 5 java tomcat maven-2

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

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

默认情况下,deploy:deploy目标似乎绑定到deploy生命周期阶段。换句话说,当deploy生命周期阶段运行时,Maven将尝试将生成的工件(在这种情况下为.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>
Run Code Online (Sandbox Code Playgroud)

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

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

art*_*tol 2

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

  • 无意冒犯,但恕我直言,您错误地使用了“部署”阶段。它与您想要执行的操作具有相同的名称,但它不是您想要的。它用于部署到 Maven 存储库。我相信你知道,“mvn install”将 war 文件安装到本地计算机的 Maven 存储库中。我会研究使用 Jenkins 之类的工具在成功构建后部署到远程服务器。哦,进行一些集成测试;-) (5认同)