首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用cargo-maven2-plugin为嵌入式Jetty指定Java系统属性

如何使用cargo-maven2-plugin为嵌入式Jetty指定Java系统属性
EN

Stack Overflow用户
提问于 2014-08-03 11:56:45
回答 1查看 1.3K关注 0票数 1

我正在尝试使用Maven Cargo插件为我的项目的集成测试启动一个嵌入式Jetty容器。使用Jetty托管的web应用程序需要传入一个指向其配置文件的Java系统属性。我如何让它与货物一起工作?

我尝试过插件的cargo.jvmargs设置,但它似乎不起作用:

代码语言:javascript
复制
<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应用程序按预期启动,但随后由于找不到预期的配置属性而终止。

EN

回答 1

Stack Overflow用户

发布于 2014-08-03 11:56:45

我想通了。我一直担心这对于嵌入式Jetty (或其他嵌入式容器)来说是不可能的,但事实是:我只是错误地传递了系统属性。

请改用<container><systemProperties><someProp>someVal</someProp></systemProperties></container>选项。例如:

代码语言:javascript
复制
<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>

事情就像预期的那样工作。耶!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25101484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档