title: How to: Run maven integration tests against a test environment (database)
body: <p>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.  </p>
  
  <p>However, I would like to connect to a test database for my integration tests. I am storing its url in </p>
  
  <pre><code>${basedir}/src/test/resources/jdbc.properties  
  </code></pre>
  
  <p>When the jetty plugin runs (jetty:run), it uses </p>
  
  <pre><code>${basedir}/src/main/resources/jdbc.propertes 
  </code></pre>
  
  <p>instead.  I tried reconfiguring the jetty plugin via the <i>classesDirectory</i> property to use </p>
  
  <pre><code>${project.build.testOutputDirectory}
  </code></pre>
  
  <p>but the test-classes directory is missing my actual compiled project classes, as well as the resources stored in</p>
  
  <pre><code>${basedir}/src/main/resources 
  </code></pre>
  
  <p>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.</p>
  
  <p>Any ideas on how to get this set up correctly?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>Well, it seems there are <a href="http://jetty.codehaus.org/jetty/maven-plugin/run-mojo.html" rel="noreferrer">configuration properties</a> on the jetty-plugin to deal with this:</p>
  
  <ul>
  <li>testClassesDirectory : The directory containing generated test classes.</li>
  <li>useTestClasspath : If true, the  and the dependencies of test will be put first on the runtime classpath.</li>
  </ul>
  
  <p>Unfortunately, they don't work.  </p>
  
  <p>Here is the relevant portion of my pom.xml:</p>
  
  <blockquote>
  <pre><code>  &lt;testResources&gt;
          &lt;testResource&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
              &lt;directory&gt;src/test/resources&lt;/directory&gt;
          &lt;/testResource&gt;
      &lt;/testResources&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;
              &lt;version&gt;6.1.26&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;contextPath&gt;/&lt;/contextPath&gt;
                  &lt;stopPort&gt;8005&lt;/stopPort&gt;
                  &lt;stopKey&gt;STOP&lt;/stopKey&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;start-jetty&lt;/id&gt;
                      &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;run&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;daemon&gt;true&lt;/daemon&gt;
                          &lt;useTestClasspath&gt;true&lt;/useTestClasspath&gt;
                          &lt;testClassesDirectory&gt;${project.build.testOutputDirectory}&lt;/testClassesDirectory&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;stop-jetty&lt;/id&gt;
                      &lt;phase&gt;post-integration-test&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;stop&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.6&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;integration-test&lt;/goal&gt;
                          &lt;goal&gt;verify&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;configuration&gt;
                  &lt;useFile&gt;false&lt;/useFile&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  </code></pre>
  </blockquote>