0

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.

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
  • you have a strange mix of jetty versions, cargo at jetty8x and jetty-maven-plugin at 6.1.26. – Joakim Erdfelt Dec 03 '13 at 15:15
  • My original problem is to have a code coverage with Jacoco when I run integration tests. I was launching Jetty6 on pre-integration-test phase but I read that it's not possible to have code coverage by this way. So now, I try to use cargo but I was reading my database configuration from test resources. The Jetty version is not important in this case. – Olivier Catteau Dec 03 '13 at 16:18
  • jetty 6 was EOL'd back in 2010. there have been over 100 releases of jetty since jetty 6.1.26. jacoco integration is probably easier accomplished with junit + embedded jetty – Joakim Erdfelt Dec 03 '13 at 16:30

1 Answers1

1

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

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Chris
  • 347
  • 1
  • 11