【问题标题】:Running Cargo From Maven antrun Plugin从 Maven antrun 插件运行 Cargo
【发布时间】:2012-06-30 19:45:37
【问题描述】:

我有一个 maven(多模块)项目,为 JBoss AS 7.1.x 创建了一些 WAR 和 EAR 文件。

出于一个目的,我需要将一个模块的一个生成的 EAR 文件部署到一个新的 JBoss 实例并运行它,针对它调用一些 REST Web 服务调用并停止 JBoss。然后我需要将这些调用的结果打包写入数据库。

目前,我正在尝试使用 CARGO 和 maven ant run 插件来执行此任务。

很遗憾,我无法让三个(maven、ant run 和 CARGO)一起玩。我没有在货物的蚂蚁示例中使用的 uberjar。如何配置 ant run 任务,以便 cargo ant 任务可以创建、启动、部署我的 JBoss?理想情况下是在另一阶段由 cargo-maven2-plugin 解包和配置的?

或者,有没有更好的方法来实现我创建数据库的目标?

我不能真正使用集成测试阶段,因为它是在打包阶段之后执行的。所以,我打算在编译阶段使用 ant run 来完成。

再次澄清:

我需要做以下事情:启动 JBoss;部署战争;等待WAR启动完成;部署 EAR 文件;等到 EAR 初始化它的数据库;调用EAR实现的一些web服务;停止 JBoss;打包数据库。

所有这些步骤都需要严格按顺序进行。

【问题讨论】:

  • 为什么不使用 cargo2 maven 插件而不是 Antrun ?
  • 我需要做以下事情:启动JBoss;部署战争; 等待直到WAR启动完成;部署 EAR 文件;等到 EAR 初始化它的数据库;调用EAR实现的一些web服务;停止 JBoss;打包数据库。如何使用 cargo2-maven 插件做到这一点?

标签: maven ant cargo maven-cargo


【解决方案1】:

following part gives you an impression how to do that。您必须更改详细信息。在给定的情况下,我使用 Tomcat。这将下载 Tomcat 存档解压缩并在本地安装 Tomcat...

 <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <configuration>
      <wait>false</wait>
      <container>
        <containerId>tomcat${tomcat.major}x</containerId>
        <zipUrlInstaller>
          <url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
          <extractDir>${project.build.directory}/extract/</extractDir>
          <downloadDir>${project.build.directory}/download/</downloadDir>
        </zipUrlInstaller>
        <output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
        <log>${project.build.directory}/cargo.log</log>
      </container>
      <configuration>
        <home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
        <properties>
          <cargo.logging>high</cargo.logging>
          <cargo.servlet.port>9080</cargo.servlet.port>
          <cargo.tomcat.ajp.port>9008</cargo.tomcat.ajp.port>
        </properties>
      </configuration>
    </configuration>
    <executions>
      <execution>
        <id>start-container</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>start</goal>
          <goal>deploy</goal>
        </goals>
        <configuration>
          <deployer>
            <deployables>
              <deployable>
                <groupId>${project.groupId}</groupId>
                <artifactId>mod-war</artifactId>
                <type>war</type>
                <pingURL>http://localhost:9080/mod-war</pingURL>
                <pingTimeout>30000</pingTimeout>
                <properties>
                  <context>mod-war</context>
                </properties>
              </deployable>
            </deployables>
          </deployer>
        </configuration>
      </execution>
      <execution>
        <id>stop-container</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>stop</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

【讨论】:

  • 帮助很大。现在我只需要弄清楚对多个部署进行排序,所有这些都在编译阶段。
  • 在编译阶段?那没有意义。我会在集成测试阶段这样做,并制作一个可以由配置文件激活的单独模块。
  • 我需要在打包前的某个阶段进行。你推荐哪一个?集成测试肯定不起作用,或者是吗?
  • 为什么在打包之前需要它?这没有意义,因为在打包之前不存在EAR等......所以最好在集成测试区域进行,因为它是一种集成测试。我已经使用此设置完成了几个项目并且效果很好。
  • 是的,EAR 确实存在,因为它是另一个模块的依赖项。这里的这个模块只做打包。没有任何编译。
猜你喜欢
  • 2011-04-16
  • 1970-01-01
  • 2011-07-06
  • 1970-01-01
  • 2011-04-17
  • 1970-01-01
  • 2016-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多