I'm using maven and the maven-failsafe-plugin to start up jetty during the integration-test lifecycle phase. I then execute a number of (*IT.java) junit tests against my running webapp. This is working as expected.
However, I would like to connect to a test database for my integration tests. I am storing its url in
${basedir}/src/test/resources/jdbc.properties
When the jetty plugin runs (jetty:run), it uses
${basedir}/src/main/resources/jdbc.propertes
instead. I tried reconfiguring the jetty plugin via the classesDirectory property to use
${project.build.testOutputDirectory}
but the test-classes directory is missing my actual compiled project classes, as well as the resources stored in
${basedir}/src/main/resources
note: surefire adds the test resources to the classpath, followed by the main resources, such that anything found in both will use the test version because it is found first in the classpath.
Any ideas on how to get this set up correctly?
Thanks!
EDIT:
Well, it seems there are configuration properties on the jetty-plugin to deal with this:
- testClassesDirectory : The directory containing generated test classes.
- useTestClasspath : If true, the and the dependencies of test will be put first on the runtime classpath.
Unfortunately, they don't work.
Here is the relevant portion of my pom.xml:
<testResources> <testResource> <filtering>true</filtering> <directory>src/test/resources</directory> </testResource> </testResources> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.26</version> <configuration> <contextPath>/</contextPath> <stopPort>8005</stopPort> <stopKey>STOP</stopKey> </configuration> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <daemon>true</daemon> <useTestClasspath>true</useTestClasspath> <testClassesDirectory>${project.build.testOutputDirectory}</testClassesDirectory> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> <configuration> <useFile>false</useFile> </configuration> </plugin>