Add test classpath to Jetty run by Cargo

907 views Asked by At

I would like to run Jetty by using Cargo but I would like to add test resources to Jetty classpath.

Here is my Maven configuration :

        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.4.5</version>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals><goal>start</goal></goals>
                    <configuration>
                        <configuration>
                            <properties>
                                <cargo.jvmargs>${argLine}</cargo.jvmargs>
                            </properties>
                        </configuration>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals><goal>stop</goal></goals>
                </execution>
            </executions>
            <configuration>
                <container>
                    <containerId>jetty8x</containerId>
                    <type>embedded</type>
                    <log>${basedir}\target\cargo.log</log>
                    <output>${basedir}\target\jetty.log</output>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                        </dependency>
                    </dependencies>
                </container>

                <configuration>
                    <properties>
                        <cargo.servlet.port>8081</cargo.servlet.port>
                        <cargo.logging>high</cargo.logging>
                        <cargo.jvmargs>${argLine} -Denv=test</cargo.jvmargs>
                    </properties>
                </configuration>

                <deployables>
                    <deployable>
                        <pingURL>http://localhost:8081/myapp/</pingURL>
                        <pingTimeout>600000</pingTimeout>
                        <properties>
                            <context>myapp</context>
                        </properties>
                    </deployable>
                </deployables>
            </configuration>
        </plugin>

Without using Cargo, I use useTestClasspath in my Jetty configuration :

            <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.26</version>
            <configuration>
                <contextPath>myapp</contextPath>
                <webAppSourceDirectory>WebContent</webAppSourceDirectory>
                <stopPort>9699</stopPort>
                <stopKey>foo</stopKey>
                <scanIntervalSeconds>0</scanIntervalSeconds>
                <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>8081</port>
                    </connector>
                </connectors>
                <useTestClasspath>true</useTestClasspath>
                <systemProperties>
                    <systemProperty>
                        <name>jettyMode</name>
                        <value>true</value>
                    </systemProperty>
                </systemProperties>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.18</version>
                </dependency>
            </dependencies>
        </plugin>

Is there any way to configure Cargo with a kind of useTestClasspath ? Thanks.

1

There are 1 answers

0
Chris On

If I understand your question correctly, then your problem is, that some of your dependencies are in <scope>test</scope> and thus they are not packaged to your war (or ear) file and will not be available in your integration (or other) tests, when working within the container.

To achieve that behaviour, you can add a dependency to the container definition just like you added the dependency to mysql-connector-java, what is missing in your config is the <type>:

<container>
         ...
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <type>jar</type>
        </dependency>
    </dependencies>
 </container>

Moreover that dependency's artfactId and groupId must resolve to a dependency that is already defined in your pom (as dependency). See here Cargo Maven2 Reference