我正在尝试使用Maven Cargo插件为我的项目集成测试启动嵌入式Jetty容器。使用Jetty托管的Web应用程序需要在指向其配置文件时传递Java系统属性。如何让它与Cargo一起使用?
我已尝试插件cargo.jvmargs
设置,但它似乎无法正常工作:
<plugin>
<!-- Launch an embedded Jetty instance hosting this project's WAR (as
well as the rps-tourney-service-app WAR it depends on) prior to running this
project's integration tests, and stop it after the integration tests. Alternatively,
for manual testing, manually run 'mvn cargo:run' to start the Jetty server,
and have Cargo wait for a 'ctrl+c' command to stop it. -->
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<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>
<configuration>
<container>
<containerId>jetty9x</containerId>
<type>embedded</type>
</container>
<configuration>
<properties>
<cargo.servlet.port>9093</cargo.servlet.port>
<cargo.jvmargs>-Drps.service.config.path=${project.build.testOutputDirectory}/rps-service-config-its.xml
-Drps.webapp.config.path=${project.build.testOutputDirectory}/rps-webapp-config-its.xml</cargo.jvmargs>
</properties>
</configuration>
<deployables>
<deployable>
<!-- The web service WAR for the application. -->
<groupId>com.justdavis.karl.rpstourney</groupId>
<artifactId>rps-tourney-service-app</artifactId>
<type>war</type>
<properties>
<context>/rps-tourney-service-app</context>
</properties>
</deployable>
<deployable>
<!-- The end-user web site WAR for the application. As this is the
current project, Cargo binds the artifact automatically. All that needs to
be done here is to configure the context path. -->
<properties>
<context>/rps-tourney-webapp</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
webapps按预期启动,但随后因为找不到预期的配置属性而死亡。
答案 0 :(得分:3)
想出来。我一直担心这对嵌入式Jetty(或其他嵌入式容器)来说是不可能的,但它是:我只是错误地传递了系统属性。
请改用<container><systemProperties><someProp>someVal</someProp></systemProperties></container>
选项。例如:
<plugin>
<!-- Launch an embedded Jetty instance hosting this project's WAR (as
well as the rps-tourney-service-app WAR it depends on) prior to running this
project's integration tests, and stop it after the integration tests. Alternatively,
for manual testing, manually run 'mvn cargo:run' to start the Jetty server,
and have Cargo wait for a 'ctrl+c' command to stop it. -->
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<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>
<configuration>
<container>
<containerId>jetty9x</containerId>
<type>embedded</type>
<!-- This works! -->
<systemProperties>
<rps.service.config.path>${project.build.testOutputDirectory}/rps-service-config-its.xml</rps.service.config.path>
<rps.webapp.config.path>${project.build.testOutputDirectory}/rps-webapp-config-its.xml</rps.webapp.config.path>
</systemProperties>
</container>
<configuration>
<properties>
<cargo.servlet.port>9093</cargo.servlet.port>
</properties>
</configuration>
<deployables>
<deployable>
<!-- The web service WAR for the application. -->
<groupId>com.justdavis.karl.rpstourney</groupId>
<artifactId>rps-tourney-service-app</artifactId>
<type>war</type>
<properties>
<context>/rps-tourney-service-app</context>
</properties>
</deployable>
<deployable>
<!-- The end-user web site WAR for the application. As this is the
current project, Cargo binds the artifact automatically. All that needs to
be done here is to configure the context path. -->
<properties>
<context>/rps-tourney-webapp</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
事情按预期工作。耶!