背景:我正在 Maven 项目中设置功能测试模块。我们使用 maven-jetty-插件 供测试用。

我已经设置了 jetty 插件 如此处所述 (为了很好地使用 Failsafe 插件),但我想做的是使用 jetty 从我们的主 Web 模块部署 war 工件(在功能测试模块运行时它刚刚安装到本地 Maven 存储库中) )。

jetty 插件的 跑战目标 有一个 <webApp> 元素,它采用要部署的战争的字符串路径。我更愿意使用我们的 Web 模块定义的 Maven 坐标来指定要部署的战争。有什么办法可以做到这一点吗?

可能的解决方法:

  1. “使用 Maven 更好地构建”第 4.13 节 描述了使用 Cargo 来部署使用 Maven 坐标指定的战争,但考虑到我们使用的是 Jetty,这是严重的矫枉过正。
  2. 更合理的IMO是使用dependency:copy将刚刚构建和安装的war工件复制到功能测试模块目标目录中的固定路径,然后我可以在jetty插件的 <webApp> 配置元素。
有帮助吗?

解决方案

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

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

《Better Builds with Maven》第4.13节描述了使用cargo部署使用maven坐标指定的war,

是的,Cargo 可以以一种干净的方式做到这一点。

但考虑到我们使用的是码头,这是严重的矫枉过正。

我不同意。首先,jetty 插件不支持你想要做的开箱即用的事情(所以它可能不是正确的工具)。第二, 严重矫枉过正 这是非常夸张的,实际上是一种误解,特别是考虑到货物对于嵌入式 Jetty 只需要很少的配置(零?)。

更合理的IMO是使用dependency:copy将刚刚构建和安装的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>

而且我认为这并不能客观地定义为“严重的杀伤力”。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top