title: Tomcat7 Maven Plugin and JaCoCo
body: <p>Is there any way to get code coverage using <a href="http://www.eclemma.org/jacoco/trunk/index.html" rel="noreferrer">JaCoCo</a> with the <a href="http://tomcat.apache.org/maven-plugin-2.1/tomcat7-maven-plugin/" rel="noreferrer">tomcat7-maven-plugin</a> embedded instance?</p>
  
  <p>The jacoco-maven-plugin is configured in my WAR's POM to instrument my unit tests, but I'm not sure how to attach the jacoco agent to the embedded Tomcat instance to instrument my integration tests that run against Tomcat. Given that the Tomcat instance is embedded, I'm not sure if this approach is possible. Is there any other way to accomplish this? I can probably switch from using the Tomcat Maven Plugin to using Cargo to get coverage, but I'd prefer to stick with the Tomcat plugin if possible.</p>
  
  <p>Here are a few relevant snippets from my POM:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;plugin&gt;
      &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
      &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;0.6.2.201302030002&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;goals&gt;
                  &lt;goal&gt;prepare-agent&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.14&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;integration-tests&lt;/id&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;/plugin&gt;
  &lt;plugin&gt;
      &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
      &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.1&lt;/version&gt;
      &lt;configuration&gt;
          &lt;systemProperties&gt;
              &lt;!-- as expected, this system property doesn't work since Tomcat is embedded, but this is the type of config I'm looking for --&gt;
              &lt;JAVA_OPTS&gt;-javaagent:${project.build.directory}/${jacoco.jar}=destfile=${project.build.directory}/jacoco.exec,append=true&lt;/JAVA_OPTS&gt;
          &lt;/systemProperties&gt;
      &lt;/configuration&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;tomcat-startup&lt;/id&gt;
              &lt;goals&gt;
                  &lt;goal&gt;run-war-only&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;phase&gt;pre-integration-test&lt;/phase&gt;
              &lt;configuration&gt;
                  &lt;fork&gt;true&lt;/fork&gt;
              &lt;/configuration&gt;
          &lt;/execution&gt;
          &lt;execution&gt;
              &lt;id&gt;tomcat-shutdown&lt;/id&gt;
              &lt;goals&gt;
                  &lt;goal&gt;shutdown&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;phase&gt;post-integration-test&lt;/phase&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>Versions: Maven 3.0.4, Tomcat Maven Plugin 2.1, Jacoco 0.6.2.201302030002, Java 7</p>