I was testing to use Apache Jmeter to load test a java class. I set up a Maven project and added Jmeter dependencies. I was using v5.4.1 JMeter.
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_java -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>5.4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_core -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>5.4.1</version>
</dependency>
</dependencies>
And below is my simple java class for testing:
package jmeter.testing;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
public class ClassTester extends AbstractJavaSamplerClient {
@Override
public SampleResult runTest(JavaSamplerContext context) {
SampleResult result = new SampleResult();
result.sampleStart();
for (int i = 0; i < 100; i ) {
System.out.println("Testing Jmeter code...");
}
result.setResponseCode("200");
result.setResponseMessage("Jmeter Test");
result.setSampleLabel("test");
result.sampleEnd();
return result;
}
}
I had Maven build this jar file and copied it to the /lib/ext directory. (My Jmeter was installed via brew..) And I didn't see this class in the Java Request Sampler somehow after I restarted JMeter. Could anyone guide me where was wrong? Thanks.
[INFO] Building jar: /Users/alex/Documents/IntelliJ/jmeter-util/target/jmeter-util-1.0-SNAPSHOT.jar
/usr/local/Cellar/jmeter/5.4.1/libexec/lib/ext
❯ ls -ltr
-rw-r--r--@ 1 alex staff 2726 Nov 11 17:16 jmeter-util-1.0-SNAPSHOT.jar
CodePudding user response:
Another solution: You will have to add your jar into the local repository and add the dependency to your pom.xml.
So check where your jmeter
is pointing using which and ls -la commands, it might be the case you have some other JMeter in your PATH which is different from ../Cellar/jmeter/5.4.1/bin/jmeter
You can check out Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for more information on creating custom Java Request sampler and other scripting approaches.
CodePudding user response:
Can you copy the jar file to ${JMETER_HOME}/bin and check if it work?
lib/ext
folder is for the Jmeter plugins. It's not for the utility jars. You can place the utility jars into the lib
folder.
Your jar file need to be in the classpath. Please see more details on the classpath configuration