如何运行jetty:使用maven坐标定义的战争进行战争?

时间:2010-02-13 17:05:11

标签: maven-2 jetty maven maven-jetty-plugin

背景:我正在maven项目中设置功能测试模块。我们使用maven-jetty-plugin进行测试。

我已经设置了Jetty插件as described here(与Failsafe插件很好地配合),但我想要做的是使用jetty从我们的主Web模块部署war工件(其中包含刚刚在功能测试模块运行时安装到本地maven仓库中。)

jetty插件的run-war goal有一个<webApp>元素,它采用字符串路径来部署战争。我更愿意使用我们的web模块定义的maven坐标来指定部署战争。有没有办法做到这一点?

可能的解决方法:

  1. Section 4.13 of "Better Builds with Maven"描述了使用货物部署使用maven坐标指定的战争,但鉴于我们正在使用码头,这是严重的过度杀伤。
  2. 更合理的IMO正在使用依赖:复制将刚构建并安装的war伪像复制到功能测试模块的目标目录中的固定路径,然后我可以在jetty插件的<webApp>配置中提供元件。

1 个答案:

答案 0 :(得分:9)

  

jetty插件的run-war目标有一个元素,它采用字符串路径来部署战争。我更愿意使用我们的web模块定义的maven坐标来指定部署战争。有没有办法做到这一点?

这不是真正应该使用的maven jetty插件,插件部署了当前模块的战争,默认情况下不支持你想要做的事情。

  

“使用Maven更好地构建”的第4.13节描述了使用货物部署使用maven坐标指定的战争,

是的,Cargo可以干净利落地做到这一点。

  

但鉴于我们正在使用码头,这是严重的过度杀伤。

我不同意。首先,jetty插件不支持你想要开箱即用的东西(所以它可能不是正确的工具)。其次,严重矫枉过正被夸大了,实际上是一种误解,特别是考虑到货物对嵌入式Jetty的配置非常少(零?)。

  

更合理的IMO正在使用依赖:复制将刚构建并安装的war伪像复制到功能测试模块的目标目录中的固定路径

没有冒犯,但你的整个问题听起来有点像:我有一把锤子,钉子很好,我可以用它作螺丝,因为得到螺丝刀似乎是一种严重的矫枉过正吗?要回答这个问题(这就是你所说的),你可以使用dependency:copy并使用maven jetty插件完成所有工作,但这是一个黑客攻击(因为你实际上并没有问任何问题)问题,我猜你想要对此提出意见)。当然最后的决定属于你:)

以防万一,以下是我如何使用Cargo实现这一点:

<dependencies>
  <dependency>
    <groupId>war group id</groupId>
    <artifactId>war artifact id</artifactId>
    <type>war</type>
    <version>war version</version>
  </dependency>
  ...
</dependencies>
...
<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <configuration>
        <!-- Container configuration -->
        <container>
          <containerId>jetty6x</containerId>
          <type>embedded</type>
        </container>
        <!-- Configuration to use with the container or the deployer -->
        <configuration>
          <deployables>
            <deployable>
              <groupId>war group id</groupId>
              <artifactId>war artifact id</artifactId>
              <type>war</type>
              <properties>
                <context>war context</context>
              </properties>
            </deployable>
          </deployables>
        </configuration>
        <!-- Don't wait, execute the tests after the container is started -->
        <wait>false</wait>
      </configuration>
      <executions>
        <execution>
          <id>start-container</id>
          <phase>pre-integration-test</phase>
          <goals>
            <goal>start</goal>
          </goals>
        </execution>
        <execution>
          <id>stop-container</id>
          <phase>post-integration-test</phase>
          <goals>
            <goal>stop</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
  ...
</build>

我并不认为这可以客观地称为“严重矫枉过正”。

相关问题