首页 文章

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

提问于
浏览
6

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

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

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

可能的解决方法:

  • Section 4.13 of "Better Builds with Maven"描述了使用货物来部署使用maven坐标指定的战争,但是's serious overkill given that we'使用了jetty .

  • 更合理的IMO正在使用依赖关系:复制将刚构建并安装的war伪像复制到功能测试模块's target directory, which I can then provide in the jetty plugin' s <webApp> 配置元素中的固定路径 .

1 回答

  • 9

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

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

    “Better Builds with Maven”第4.13节描述了使用货物部署使用maven坐标指定的战争,

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

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

    我不支持您想要开箱即用的东西(所以它可能不是正确的工具) . 其次,严重的矫枉过正被夸大了,实际上是一种误解,特别是考虑到货物对嵌入式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>
    

    而且我认为这不能客观地称为“严重过度杀伤力” .

相关问题