【问题标题】:How to specify Java system properties for embedded Jetty with cargo-maven2-plugin如何使用 cargo-maven2-plugin 为嵌入式 Jetty 指定 Java 系统属性
【发布时间】:2014-09-25 21:52:56
【问题描述】:

我正在尝试使用 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 按预期启动,但随后由于未找到预期的配置属性而死。

【问题讨论】:

    标签: maven jetty embedded-jetty cargo


    【解决方案1】:

    想通了。我一直担心嵌入式 Jetty(或其他嵌入式容器)无法做到这一点,但事实是:我只是错误地传递了系统属性。

    请改用&lt;container&gt;&lt;systemProperties&gt;&lt;someProp&gt;someVal&lt;/someProp&gt;&lt;/systemProperties&gt;&lt;/container&gt; 选项。例如:

    <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>
    

    一切都按预期进行。耶!

    【讨论】:

      猜你喜欢
      • 2011-08-05
      • 2014-12-19
      • 1970-01-01
      • 2011-03-15
      • 2011-01-31
      • 1970-01-01
      • 2011-03-22
      • 1970-01-01
      • 2011-05-01
      相关资源
      最近更新 更多