title: How to pack a JMeter test plan built from code into a jar using Maven?
body: <p>I'm attempting to build a JMeter test plan in Java. I can't seem to find much documentation on this process, and the resources I can find all use Maven to build the jar. I have no prior experience with Maven and cannot get my pom configuration right.</p>
  
  <p>Main points of confusion:</p>
  
  <ul>
  <li><p>If my jar goes in jmeter_home/lib/ext, does that make dependencies like ApacheJMeter_core and ApacheJMeter_http a provided situation?</p></li>
  <li><p>There seem to be multiple Maven plugins (maven-jar, maven-assembly) with a similar purpose? Is there one that best suits my needs?</p></li>
  <li><p>If I want to reference a non java resource in a place outside of the jar (somewhere else in the JMeter directory), does that require special consideration when configuring your POM?</p></li>
  <li><p>Am I supposed to configure the jar to be executable, or does JMeter provide like a script to work with lib/ext jars?</p></li>
  </ul>
  
  <p>Any insight on any of these points would be greatly appreciated.</p>
  
  <p>These resources have guided me along, but I've wasted hours trying to solve this seemingly menial piece of the process..</p>
  
  <p><a href="https://bitbucket.org/blazemeter/jmeter-from-code/" rel="nofollow noreferrer">https://bitbucket.org/blazemeter/jmeter-from-code/</a></p>
  
  <p><a href="https://github.com/piotrbo/jmeterpoc" rel="nofollow noreferrer">https://github.com/piotrbo/jmeterpoc</a></p>
  
  <p>If anyone has more resources on building JMeter test plans in code, PLEASE feel free to share!</p>
  
  <p>Here's my pom.xml, I understand that there's probably some redundancy in my use of plugins and such, but that happens when you've been attacking the same problem for hours with no progress :)</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
  http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.sweber&lt;/groupId&gt;
      &lt;artifactId&gt;jmeter-plugin&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;name&gt;jmeter-plugin&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
      &lt;build&gt;
  
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;copy-dependencies&lt;/id&gt;
                          &lt;phase&gt;prepare-package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;copy-dependencies&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;outputDirectory&gt;
                                  ${project.build.directory}/lib
                              &lt;/outputDirectory&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;archive&gt;
                          &lt;manifest&gt;
                              &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                              &lt;classpathPrefix&gt;lib/&lt;/classpathPrefix&gt;
                              &lt;mainClass&gt;
                                  com.sweber.Main
                              &lt;/mainClass&gt;
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;single&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;archive&gt;
                                  &lt;manifest&gt;
                                      &lt;mainClass&gt;
                                          com.sweber.Main
                                      &lt;/mainClass&gt;
                                  &lt;/manifest&gt;
                              &lt;/archive&gt;
                              &lt;descriptorRefs&gt;
                                  &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
                              &lt;/descriptorRefs&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  
          &lt;/plugins&gt;
  
      &lt;/build&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.jmeter&lt;/groupId&gt;
              &lt;artifactId&gt;ApacheJMeter_core&lt;/artifactId&gt;
              &lt;version&gt;5.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.jmeter&lt;/groupId&gt;
              &lt;artifactId&gt;ApacheJMeter_java&lt;/artifactId&gt;
              &lt;version&gt;5.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.jmeter&lt;/groupId&gt;
              &lt;artifactId&gt;ApacheJMeter_http&lt;/artifactId&gt;
              &lt;version&gt;5.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi&lt;/artifactId&gt;
              &lt;version&gt;4.0.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
              &lt;version&gt;4.0.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;kg.apc&lt;/groupId&gt;
              &lt;artifactId&gt;jmeter-plugins-casutg&lt;/artifactId&gt;
              &lt;version&gt;2.7&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>