我想使用Cargo运行Jetty,但我想将测试资源添加到Jetty类路径。
这是我的Maven配置:
<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>
在不使用Cargo的情况下,我在Jetty配置中使用 useTestClasspath :
<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>
有没有办法用一种 useTestClasspath 来配置Cargo? 感谢。
答案 0 :(得分:1)
如果我正确理解了您的问题,那么您的问题是,您的某些依赖项位于<scope>test</scope>
中,因此它们不会打包到您的war(或ear)文件中,并且在您的集成中不可用(或者在容器内工作时进行其他测试。
要实现这种行为,您可以向容器定义添加依赖项,就像将依赖项添加到mysql-connector-java一样,配置中缺少的是<type>
:
<container>
...
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<type>jar</type>
</dependency>
</dependencies>
</container>
此外,依赖项的artfactId和groupId 必须解析为已在pom中定义的依赖项(作为依赖项)。见Cargo Maven2 Reference