我正在尝试使用Maven Cargo插件为我的项目的集成测试启动一个嵌入式Jetty容器。使用Jetty托管的web应用程序需要传入一个指向其配置文件的Java系统属性。我如何让它与货物一起工作?
我尝试过插件的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>not应用程序按预期启动,但随后由于找不到预期的配置属性而终止。
发布于 2014-08-03 11:56:45
我想通了。我一直担心这对于嵌入式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>事情就像预期的那样工作。耶!
https://stackoverflow.com/questions/25101484
复制相似问题