7. Building the JMeter Script Artefacts

Using a Maven build to create the Script Artefacts required for JMeter deployment and execution.

Maven is the assumed build tool for projects creating Mark59 script artefacts that are to be deployed and executed in JMeter, and is the focus of this chapter.

Scripting Dependencies

A general discussion of Mark59 project dependencies has been covered in an earlier chapter. The pom.xml file for the dataHunterPVTest project outlines the dependencies required for a Mark59 Script Project. The fundamental requirement for a Mark59 project is the inclusion of the mark59-selenium-implementation dependency.

<dependency>
<groupId>com.mark59</groupId>
<artifactId>mark59-selenium-implementation</artifactId>
<version>2.2</version>
</dependency>

Note that the pom.xml for the dataHunterPVTest project doesn't actually include it - but that's only because the project includes a dependency on mark59-selenium-sample-dslwhich itself has a dependency on mark59-selenium-implementation.

The other dependency that needs to be added is for the jmeter classes - this is scoped as provided, since the classes will be available in the run-time environment (JMeter).

<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>{target JMeter installation version}</version>
<scope>provided</scope>
</dependency>

We recommend NOT using JMeter version 5.2, if you are, just go to 5.2.1 or latest release (5.2 had a nasty dependency issue in its pom structure).

The Maven Build

JMeter requires that for a Java Request Sampler (which is what a Mark59 Selenium script is to JMeter), a jar containing the script, and possibly other jar dependencies, need to be placed in the lib/ext directory of JMeter. We use the Maven build with goals of clean package to build this jar file.

In most cases, a Maven plugin can be used that will successfully package the script logic, and all its dependencies, into a single jar. The dataHunterPVTest pom.xml file is set up to do this by the use of the maven assembly plugin.

<build>
<plugins>
<!-- Maven Assembly Plugin (alternative to Maven Jar Plugin and Dependency Plugin usage above) -->
<!-- phase/goals: clean package -->
<!-- Wraps all the project classes and their dependencies into an single Jar (to be copied to lib/ext of target Jmeter instance) -->
<!-- Note that this is not a general solution. May not work for projects with complex dependency trees (version issues), JCE providers (like bouncy castle) -->
<!-- In those projects use the Maven Jar and Dependency Plugins as described above -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals><goal>single</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>

Unfortunately, there are certain dependency jars which will not 'squash up' into one big jar. A common example of such a dependency is the JCE provider 'bouncy castle', but there are other situations and jars that cause problems. In this case a more general solution is provided (in the dataHunterPVTest pom.xml file it has been commented out). It produces a jar and a library of dependency jars, both of which must be placed in the lib/ext folder of JMeter. The build works by using the maven-jar-plugin to create manifest entries in the 'main' jar that lists all the jars in the dependency library, which is constructed using the maven-dependency-plugin.

<build>
<plugins>
<!-- Maven Jar Plugin and Dependency Plugin -->
<!-- phase/goals: clean package -->
<!-- The plugins work in conjunction here to produce an output Jar and a directory of its dependencies -->
<!-- (both to be copied to lib/ext of target Jmeter instance) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>./${project.artifactId}-dependencies</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.artifactId}-dependencies</outputDirectory>
<excludeGroupIds>org.apache.jmeter</excludeGroupIds>
</configuration>
</execution>
</executions>
</plugin>
<finalName>${project.artifactId}</finalName>
</build>
A jar and dependency library built using maven-jar-plugin and maven-dependency-plugin