Skip to content

Maven JMeter Plugin

The Maven JMeter Plugin allows you to automate JMeter tests in Maven.  It was originally borrowed from here

The JMeter jar was build off of JMeter 2.3.2.

Here are the steps needed to get the JMeter Maven plugin working for you.  This list is mostly borrowed from James’ original documentation on the subject.

1. Download the support jars and install them.

Unzip the file, and then use mvn to install the jars in your repo using the following command (again, thanks James).

mvn deploy:deploy-file -DgroupId=org.apache.jmeter -DartifactId=jmeter -Dversion=2.3 -Dpackaging=jar -Dfile=jmeter-2.3.jar -DpomFile=jmeter-2.3.pom -Durl=file://<repo dir>
mvn deploy:deploy-file -DgroupId=jcharts -DartifactId=jcharts -Dversion=0.7.5 -Dpackaging=jar -Dfile=jcharts-0.7.5.jar
-Durl=file://<repo dir>
mvn deploy:deploy-file -DgroupId=org.apache.jorphan -DartifactId=jorphan -Dversion=2.3 -Dpackaging=jar -Dfile=jorphan-2.3.jar -Durl=file://<repo dir>
mvn deploy:deploy-file -DgroupId=org.mozilla.javascript -DartifactId=javascript -Dversion=1.0 -Dpackaging=jar -Dfile=javascript-1.0.jar -Durl=file://<repo dir>

2. Download the maven Jmeter Plugin and install it.

Unzip the file, and then use mvn to install this jar in your repo.

mvn deploy:deploy-file -DgroupId=org.apache.jmeter -DartifactId=maven-jmeter-plugin -Dversion=1.0 -Dpackaging=jar -Dfile=maven-jmeter-plugin-1.0.jar -DpomFile=maven-jmeter-plugin-1.0.pom -Durl=file://<repo dir>

3. Add the dependency to your project pom

Add the following to your pom:

<plugin>
    <groupId>org.apache.jmeter</groupId>
    <artifactId>maven-jmeter-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <id>jmeter-tests</id>
            <phase>verify</phase>
            <goals>
                <goal>jmeter</goal>
            </goals>
       </execution>
    </executions>
    <configuration>
        <reportDir>${project.build.directory}/jmeter-reports</reportDir>
        <jmeterUserProperties>
            <!-- for user properites -->
        </jmeterUserProperties>
    </configuration>
</plugin>

I’ll go over some of the options later.

4. Create some JMeter tests

This one should be simple enough, unless you don’t know about JMeter.  It can be a bit daunting and counterintuitive at first, but once you start to get the hang of it, it will be like second nature, and you will realize how powerful the tool can be.

Once you create your JMeter tests, you’ll want to copy them to <Project Dir>/src/test/jmeter.

5. Copy over jmeter.properties

Oh, you do have JMeter, right?  Else you wouldn’t have been able to do step 4.  Copy <JMETER_HOME>/bin/jmeter.properties to <Project Dir>/src/test/jmeter.  You can makeany tweats necessary to the jmeter.properties file you see fit.

6. Run mvn verify

All your tests should run in maven now!

<jmeterUserProperties>

In this section, you can define properties in JMeter files.  For example, you could define a hostname in your JMeter test like this:

${__P(someVariableName, localhost)

Then, in your pom.xml, you can define that variable like so:

<jmeterUserProperties>
   <someVariableName>hostname.com</someVariableName>
</jmeterUserProperties>

This has the same effect as using -D on the command line, as described here (search for section 2.4.7).

You should now have all you need to run maven-jmeter-plugin.

16 Comments
  1. Tarun permalink

    Hello Tom,

    Thanks for the enhancements made to James work.

    I was able to generate html reports from the James tutorial but I was not able to get any benefit of your work.
    I am not a programmer so If possible can you make documentation for these steps more elaborative.
    some of my doubts are:
    1) for steps 1 and 2 full command for mvn deploy with the repository path
    2) full content and location and filename of the pom file
    3) command for generating html reports using your plugin

    Thanks in advance.

    Regards
    Tarun Prakash

  2. jmatute permalink

    Hi Ron,

    Thanks for the really nice work upgrading the plugin to the latest version of Jmeter and adding new features!.
    We are currently starting to use it to automate our performance tests without any problems.
    However, in my tests I found a curiosity regarding the plugin exit logic that might hit somebody else, so I though it was worth mentioning.

    I used a jetty container to do the tests with the plugin, triggering them in the maven integration phase, where also the Jetty container is automatically started prior the execution of Jmeter tests.
    Currently, the plugin exits when the number of threads drop to the number just before the Jmeter start call. This will normally work in most situations except in my tests, where a Jetty is spawned by maven and the Jmeter tests will hit that Jetty with the subsequent threads spawned to handle the connections. Those threads are obviously also considered by the exit logic.
    The effect is that the plugin delays it exit until those connection threads time-out.

    Normally we will use Jmeter tests not in a maven spawned Jetty container, but nevertheless worth mentioning considering that many people will test the plugin to see if it fits their needs in a similar way I did.

    In order to continue with my tests and avoid the delays, I used the solution posted in the original plugin page (that monitors the jmeter.log). Probably the best approach would be to monitor only JMeter related threads. That needs a bit more of investigation.

    Jacobo

  3. Ronnie permalink

    Hello Tarun.

    For steps 1 and 2, your repository directory is typically going to be $HOME/.m2. This is where you want to install the jar file to, and the maven command will do it.

    A good source for more information is directly on maven’s site itself:

    http://maven.apache.org/

  4. Hey Ron,
    Great article, I have a question in relation to how the JMeter plugin handles the classpath details. can you let us know where the classpath is picked up from. Usually JMeter uses the classpath set in the user.classpath setting from jmeter.properties. So using the plugin does JMeter pick up classpath from 1. Current maven classpath or 2. jmeter.properties from the src/test/jmeter folder or 3. jmeter.properties from classes/test/jmeter/

    Thanks

    Noel

  5. Hi All,

    Will just update you here on the classpath issue I am having. After looking at the plugin code it does not touch the classpath and simply sets the program to take user.properties from @parameter expression=”${basedir}/src/test/jmeter/jmeter.properties”.

    You should be able to see the classpath being set in your jmeter.log file.

    Cheers,

    Noel

  6. Matt permalink

    I keep getting this error: ERROR – jmeter.threads.JMeterThread: Test failed! java.lang.NoClassDefFoundError: org/htmlparser/util/NodeIterator

  7. summer permalink

    my test project use jmeter maven plugin throw ClassNotFoundException

  8. Bogdan permalink

    Hello,

    I’ve done the steps described there, it’s fine. It tries to execute the jmx file, but I receive this error:
    [INFO] Executing test: /home/bogdan/emma/src/test/jmeter/Test1.jmx
    Error in NonGUIDriver java.lang.NullPointerException
    [ERROR] BUILD FAILURE
    And in generated jmeter.log files it says:
    2010/01/19 16:42:45 ERROR – jmeter.JMeter: java.lang.NullPointerException
    at org.apache.jmeter.gui.tree.JMeterTreeModel.addSubTree(JMeterTreeModel.java:91)
    at org.apache.jmeter.JMeter.run(JMeter.java:728)
    at org.apache.jmeter.JMeter.startNonGui(JMeter.java:706)
    at org.apache.jmeter.JMeter.start(JMeter.java:361)
    at org.apache.jmeter.JMeterMojo.executeTest(JMeterMojo.java:223)
    at org.apache.jmeter.JMeterMojo.execute(JMeterMojo.java:100)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)

    And in

  9. Bogdan permalink

    Regarding my previous post, I have to mention I want to execute my JMX script in Non GUI mode.

    Sorry for not mentioning this previously.

  10. jared permalink

    Hello,

    Have you posted the source code for this anywhere? I’d be curious at taking a peak to see how much has changed since the original version.

    Thanks,
    Jared

  11. Ronnie permalink

    I haven’t looked at this stuff in a really long time. The code exists here:

    http://code.google.com/p/jmeter-maven-plugin/

    Someone was contacting me about trying to get it into the maven repository, but I haven’t heard from him in a long time. Please feel free to improve it.

    What I basically had to do with JMeter was tear apart the jmeter jar and repackage it so that it could basically be used as an external library as opposed to a “main” program (if that makes sense). I did that with the new version of Jmeter (2.3.2 at the time).

  12. I am getting the following exception; what jar am I missing?
    2010/03/17 09:35:11 ERROR – jmeter.threads.JMeterThread: Test failed! org.apache.jmeter.protocol.http.parser.HTMLParseError
    at org.apache.jmeter.protocol.http.parser.HTMLParser.getParser(HTMLParser.java:98)
    at org.apache.jmeter.protocol.http.parser.HTMLParser.getParser(HTMLParser.java:74)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.downloadPageResources(HTTPSamplerBase.java:715)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.resultProcessing(HTTPSamplerBase.java:946)
    at org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:474)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:658)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:647)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)
    at java.lang.Thread.run(Thread.java:637)
    Caused by: java.lang.ClassNotFoundException: org.apache.jmeter.protocol.http.parser.HtmlParserHTMLParser
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at org.apache.jmeter.protocol.http.parser.HTMLParser.getParser(HTMLParser.java:87)
    … 8 more

  13. Agata permalink

    Hi,

    I add
    to pom.xml, and also properties to my test.jmx,

    But when I run test by maven, the properties are not read. and test fail.

    Should I install anythig else, to use jmeterUserProperties?

Trackbacks & Pingbacks

  1. This is my blog » maven-jmeter-plugin release
  2. Custom Plugins for Jmeter «
  3. This is my blog » A better JMeter Maven plugin

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS