This is a Maven 2 plugin that allows you to run JMeter tests as part of the build. I am using this with JChav and Continuum to automate the running of a suite of JMeter load tests, and publish the results to a web page. Sorry this is not more polished. It could use some TLC to make it more user-friendly to actually plug it into a project. I just thought I'd stick the code out there as quickly as possible and see if anyone is interested in it before I went any further with it.

To build and use the plugin:

Remote Repository

Deploy JMeter Jar

Deploy Dependencies

Install the Plugin

Configure the Plugin

Executing the Plugin

Change to the plugin - by Peter Andersen / not committed!

(If this can be used - please commit this into the codebase)

Using jmeter from maven-jmeter-plugin as suggested on:

http://jlorenzen.blogspot.com/2008_03_01_archive.html

The problem is that maven hang after the test has ended.

Some debugging shows that the maven-jmeter-plugin call to jmeter course jmeter to leak threads, I have done the following change to the maven-jmeter-plugin that fixes the problem, using checkForEndOfTest method below.

Hope someone can use this to improve the plugin.

Code changes to org.apache.jmeter.JMeterMojo.java:

	private void executeTest(File test) throws MojoExecutionException {
		/...	cut out from mail
			try {
				// This mess is necessary because the only way to know when JMeter
				// is done is to wait for all of the threads that it spawned to exit.
				new JMeter().start(args.toArray(new String[]{}));
				BufferedReader in = new BufferedReader(new FileReader(jmeterLog));
				while (!checkForEndOfTest(in)) {
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						break;
					}
				}
				in.close();
			} catch (ExitException e) {
				if (e.getCode() != 0) {
					throw new MojoExecutionException("Test failed", e);
				}
			} finally {
				System.setSecurityManager(oldManager);
				Thread.setDefaultUncaughtExceptionHandler(oldHandler);
			}
		} catch (IOException e) {
			throw new MojoExecutionException("Can't execute test", e);
		}
	}

	private boolean checkForEndOfTest(BufferedReader in) throws MojoExecutionException {
		boolean testEnded = false;
		try {
			String line;
			while ( (line = in.readLine()) != null) {
				if (line.indexOf("Test has ended") != -1) {
					testEnded = true;
					break;
				}
			}
		} catch (IOException e) {
			throw new MojoExecutionException("Can't read log file", e);
		}
		return testEnded;
	}