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:
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>
I have about the same problem, and solved it by using a custom web.xml (jettyweb.xml) see the maven configuarion
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<overrideWebXml>./src/main/webapp/WEB-INF/jettyweb.xml</overrideWebXml>
<scanintervalseconds>3</scanintervalseconds>
</configuration>
<dependencies>
</dependencies>
</plugin>
</plugins>
</build>
In my case I use this configuration to use some other spring configuration to manage transactions. But this strategy could also be used to use other property files.
My original web.xml has this spring configuration
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-hibernate.xml,
/WEB-INF/spring-services.xml
</param-value>
</context-param>
My jettyweb.xml has this spring configuration
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-hibernate-jetty.xml,
/WEB-INF/spring-services.xml
</param-value>
</context-param>
This should put you on the correct path