title: Configuring Integration Tests using Spring/Jetty (or Tomcat)/Maven for REST tests
body: <p>I would like to test our REST service with HTTP requests (kinda blackbox testing). However, after a couple of hours googling and trying different configs, I am still not able to start Jetty correctly. Here is the my current configuration (I tried multiple different versions):</p>
  
  <p>pom.xml</p>
  
  <pre><code>        ...
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.8&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;junitArtifactName&gt;junit:junit&lt;/junitArtifactName&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;**/*_Roo_*&lt;/exclude&gt;
                      &lt;exclude&gt;**/*Util*&lt;/exclude&gt;
                      &lt;exclude&gt;**/*IT*&lt;/exclude&gt;
                  &lt;/excludes&gt;
                  &lt;forkMode&gt;once&lt;/forkMode&gt;
                  &lt;argLine&gt;-javaagent:'${settings.localRepository}/org/springframework/spring-instrument/${org.springframework-version}/spring-instrument-${org.springframework-version}.jar' -javaagent:'${settings.localRepository}/org/aspectj/aspectjweaver/${org.aspectj-version}/aspectjweaver-${org.aspectj-version}.jar'&lt;/argLine&gt;
                  &lt;useSystemClassLoader&gt;true&lt;/useSystemClassLoader&gt; 
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.8&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;forkMode&gt;once&lt;/forkMode&gt;
                  &lt;argLine&gt;-javaagent:'${settings.localRepository}/org/springframework/spring-instrument/${org.springframework-version}/spring-instrument-${org.springframework-version}.jar' -javaagent:'${settings.localRepository}/org/aspectj/aspectjweaver/${org.aspectj-version}/aspectjweaver-${org.aspectj-version}.jar'&lt;/argLine&gt;
                  &lt;useSystemClassLoader&gt;false&lt;/useSystemClassLoader&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;integration-test&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;integration-test&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;verify&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;verify&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&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.10&lt;/version&gt;  
              &lt;configuration&gt;  
                  &lt;scanintervalseconds&gt;10&lt;/scanintervalseconds&gt;  
                  &lt;stopkey&gt;foo&lt;/stopkey&gt;  
                  &lt;stopport&gt;9999&lt;/stopport&gt;  
                  &lt;contextpath&gt;/${project.artifactId}&lt;/contextpath&gt;  
                  &lt;connectors&gt;  
                      &lt;connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"&gt;  
                          &lt;port&gt;9090&lt;/port&gt;  
                      &lt;/connector&gt;  
                  &lt;/connectors&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;scanintervalseconds&gt;0&lt;/scanintervalseconds&gt;  
                          &lt;daemon&gt;true&lt;/daemon&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;
          ...
  </code></pre>
  
  <p>orm.xml</p>
  
  <pre><code>&lt;!-- &lt;context:load-time-weaver/&gt; --&gt;
  &lt;context:load-time-weaver weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/&gt;
  &lt;context:spring-configured/&gt;
  &lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.example.jump.domain"&gt;
      &lt;context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/&gt;
  &lt;/context:component-scan&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  </code></pre>
  
  <p>Right now, I am getting the exception:</p>
  
  <ul>
  <li>java.lang.IllegalStateException: ClassLoader [org.mortbay.jetty.webapp.WebAppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar</li>
  </ul>
  
  <p>I understand the exception, but I wasn't able to fix it. I also tried a couple of other approaches, like giving the javaagent via MAVEN_OPTS or trying to set VM args to Jetty. The problem is Google gives back a bunch of 'solutions' for different versions and none was working.</p>
  
  <p>I am currently pretty frustrated that a common scenario like doing REST services tests, is so hard to achieve in Spring. So if you are clever enough to find the right configuration, please share it with me in a way that even a monkey could configure it and I promise if we ever met the beers are on me.</p>
  
  <p>Here are the versions I use:</p>
  
  <pre><code>&lt;properties&gt;
      &lt;java-version&gt;1.6&lt;/java-version&gt;
      &lt;org.springframework-version&gt;3.0.5.RELEASE&lt;/org.springframework-version&gt;
      &lt;org.aspectj-version&gt;1.6.9&lt;/org.aspectj-version&gt;
      &lt;org.slf4j-version&gt;1.5.10&lt;/org.slf4j-version&gt;
      &lt;redis.version&gt;1.0.0.BUILD-SNAPSHOT&lt;/redis.version&gt;
      &lt;org.jboss.hibernate.version&gt;3.6.0.Final&lt;/org.jboss.hibernate.version&gt;
      &lt;net.sf.ehcache.version&gt;2.3.1&lt;/net.sf.ehcache.version&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p>Maven 2.21</p>
  
  <p>I happily provide more information if needed. Like I said every help appreciated.</p>