So I created a folder under 'resources' folder as JMeter home:
And I have the following code to run a JMX file:
// JMeter Engine
StandardJMeterEngine jmeter = new StandardJMeterEngine();
// Initialize Properties, logging, locale, etc.
File jmeterProperties = new ClassPathResource("/jmeter/JMeterHome/bin/jmeter.properties").getFile();
JMeterUtils.loadJMeterProperties(jmeterProperties.getAbsolutePath());
File jmeterHome = new ClassPathResource("/jmeter/JMeterHome").getFile();
JMeterUtils.setJMeterHome(jmeterHome.getAbsolutePath());
JMeterUtils.initLocale();
// Initialize JMeter SaveService
SaveService.loadProperties();
// Load existing .jmx Test Plan
File jmx = new ClassPathResource("/jmeter/some-test.jmx").getFile();
HashTree testPlanTree = SaveService.loadTree(jmx);
// Run JMeter Test
jmeter.configure(testPlanTree);
jmeter.run();
However, I get ClassNotFoundException and that's because none of the jar files within lib folder are being loaded
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : com.tag.jmeter.ext.config.PropertyReader
class : org.apache.jorphan.collections.ListedHashTree
required-type : org.apache.jorphan.collections.ListedHashTree
converter-type : org.apache.jmeter.save.converters.HashTreeConverter
path : /jmeterTestPlan/hashTree/hashTree/com.tag.jmeter.ext.config.PropertyReader
The thing is a lot of these jar files are not even in maven repo and there are so many of them. What is the best way to include them in classpath or have I missed something here?
Temporarily I added the following dependency and it worked but this isn't the right solution:
<dependency>
<groupId>all</groupId>
<artifactId>all</artifactId>
<version>1.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jmeter/JMeterHome/lib/tag-jmeter-extn-1.1.jar</systemPath>
</dependency>
Please note that, I am writing a series of util classes to run jmx files and this is going to be a shared util project that can be used in other projects as dependency to run their jmx files.
This is my pom dependencies:
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>2.13</version>
<exclusions>
<exclusion>
<artifactId>commons-math3</artifactId>
<groupId>commons-math3</groupId>
</exclusion>
<exclusion>
<artifactId>commons-pool2</artifactId>
<groupId>commons-pool2</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_http</artifactId>
<version>2.13</version>
<exclusions>
<exclusion>
<artifactId>commons-math3</artifactId>
<groupId>commons-math3</groupId>
</exclusion>
<exclusion>
<artifactId>commons-pool2</artifactId>
<groupId>commons-pool2</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_components</artifactId>
<version>2.13</version>
<exclusions>
<exclusion>
<artifactId>commons-math3</artifactId>
<groupId>commons-math3</groupId>
</exclusion>
<exclusion>
<artifactId>commons-pool2</artifactId>
<groupId>commons-pool2</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_config</artifactId>
<version>2.13</version>
<exclusions>
<exclusion>
<artifactId>commons-math3</artifactId>
<groupId>commons-math3</groupId>
</exclusion>
<exclusion>
<artifactId>commons-pool2</artifactId>
<groupId>commons-pool2</groupId>
</exclusion>
</exclusions>
</dependency>
As you can see we are using JMeter v 2.13 and I can't upgrade because there are hundreds of jmx written with this version and upgrading is not an option at the moment.