【问题标题】:How to bind two plugins in Maven如何在 Maven 中绑定两个插件
【发布时间】:2016-03-28 21:18:10
【问题描述】:

使用 Maven,我需要将 Web 应用程序自动部署到 Tomcat 服务器,然后运行 ​​MainClass 以执行一些部署后操作。

通过 cargo-maven2-pluginexec-maven-plugin 单独这两件事已经开始工作了。但是我不知道如何将它们绑定在一起。

我看到两个选项:

  • 将“官方”maven deploy 目标设为简单地执行 cargo-plugin,然后执行 exec-maven,仅此而已

  • exec-maven的执行绑定到cargo:deploy

  • 的完成

第一个是我的最爱。不幸的是,我不知道如何实现它们。

当前的 pom.xml:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.4.15</version>
    <configuration>
        <container>
            <containerId>tomcat8x</containerId>
            <type>remote</type>
            <systemProperties>
                <cargo.jvmargs>-XX:MaxPermSize=256M -Xmx1024m</cargo.jvmargs>
            </systemProperties>
        </container>
        <configuration>
            <type>runtime</type>
            <properties>
                <cargo.hostname>${my.hostname}</cargo.hostname>
                <cargo.servlet.port>${my.port}</cargo.servlet.port>
                <cargo.tomcat.manager.url>${my.hostname}/manager</cargo.tomcat.manager.url>
                <cargo.remote.username>tomcat</cargo.remote.username>
                <cargo.remote.password>tomcat</cargo.remote.password>
            </properties>
        </configuration>
        <deployables>
            <deployable>
                <location>${project.build.directory}/${project.build.finalName}.war</location>
                <type>war</type>
                <properties>
                    <context>/${project.build.finalName}</context>
                </properties>
            </deployable>
        </deployables>
    </configuration>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.4.0</version>
    <executions>
        <execution>
            <!-- NEED TO BE AFTER DEPLOY -->
            <phase>package</phase>
            <goals>
                <goal>java</goal>
            </goals>
            <configuration>
                <mainClass>ch.MainClass</mainClass>
                <arguments>
                    <argument>Will be forwarded to main()</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

【问题讨论】:

    标签: maven tomcat deployment maven-cargo exec-maven-plugin


    【解决方案1】:

    我建议将 cargo-maven2-plugin 绑定到 pre-integration-test 阶段,并将 exec-maven-plugin 绑定到 integration-test 阶段,该阶段在 package 阶段之后。另请参阅有关 default life cycle phases 的文档。

    deploy 阶段通常用于将生成的工件部署到 maven 存储库,因此将运行集成测试绑定到此阶段实际上没有意义。

    <plugin>
        <groupId>...</groupId>
        <artifactId>...</artifactId>
        <version>...</version>
        <executions>
            <execution>
                <phase>integration-test</phase>
                <goals>
                    <goal>xxxx</goal>
                </goals>
                <configuration>
                   ....
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    上面的配置可以同时应用到你的插件 exec-maven-plugin 和 cargo-maven2-plugin...

    最好的方法是将此类集成测试场景分离到一个单独的模块中,或者如果您只有一个模块,请使用配置文件来激活集成测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      相关资源
      最近更新 更多