Developing JMeter plugins using Maven

Jan Kronquist

I have been using JMeter for load testing and I needed to create a custom plugin to handle parsing JSON results but I couldn't find a simple guide how to do this. I wanted a simple solution that didn't require manual installation in my repository or a repository manager such as Nexus.

Building the plugin

Building a plugin using maven is easy, simply add the following to your pom:

 
<properties>
	<jmeter.home>installation directory of jmeter</jmeter.home>
</properties>
 
<dependencies>
	<dependency>
		<groupId>org.apache.jmeter</groupId>
		<artifactId>jmeter-core</artifactId>
		<version>2.3.4</version>
		<scope>system</scope>
		<systemPath>${jmeter.home}/lib/ext/ApacheJMeter_core.jar</systemPath>
	</dependency>
	<dependency>
		<groupId>org.apache.jmeter</groupId>
		<artifactId>jmeter-jorphan</artifactId>
		<version>2.3.4</version>
		<scope>system</scope>
		<systemPath>${jmeter.home}/lib/jorphan.jar</systemPath>
	</dependency>
</dependencies>

You probably want to put jmeter.home in your settings.xml instead.

Testing the plugin

Whenever I develop something I want to have a quick build/test cycle. In this case I want to to start the JMeter UI without having to update the JMeter installation or any other manual work. I didn't get chronos to add my plugin to the UI. It seems chronos copied the jar files to JMETER_HOME/lib/junit and this probably works for running an already created test, but not for creating the test. I also failed to the the maven exec plugin to create the command line arguments I needed. Instead I added a small ant script to start JMeter:

<build>
<plugins>
<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-antrun-plugin</artifactId>
      <configuration>
        <tasks>
<property name="runtime_classpath"
           refid="maven.runtime.classpath" />
          <exec executable="${jmeter.home}/bin/jmeter.bat">
            <arg value="-Jsearch_paths=${runtime_classpath}" />
          </exec>
        </tasks>
      </configuration>
    </plugin>
  </plugins>
</build>

To run the jmeter gui simply run mvn antrun:run. This only works for Windows, I leave other platforms as an exercise to the reader :-) .

Using the plugin

I ended up copying the plugin jar and dependencies to the JMeter installation and used then this modified JMeter distribution when performing the tests. The reason was that I didn't have maven installed on some of the test clients. To copy dependencies you can use mvn dependency:copy-dependencies.
If you want to run JMeter using maven you probably want to look at chronos (although it is not released it seems to work fine):

Jan Kronquist
Consultant at Jayway

Tags: , , ,

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment