BerandaComputers and TechnologyHow to run code from a JAR file inside a JMeter project

How to run code from a JAR file inside a JMeter project

I’ve been using Apache JMeter quite a lot more lately and have been finding it a very useful tool for automating some repetitive tasks that we have to perform around system maintenance on one of my projects. However, not everything can be done with what’s available in JMeter out of the box and sometimes you just need to run some external Java code from a JAR file.

For various reasons I’m still using JMeter 2.x, but this same approach should work in later versions.

In the JMeter install directory there is a lib directory and an ext directory within that. I like to place any external JAR into the lib/ext directory. JMeter does need to be restarted after copying the JAR file over, it will not detect changes automatically.


In this case I’m using the CaseUtils class from the Apache Commons Text API as an example. The JAR file for it can be downloaded from here.


Using a JSR223 Sampler, and the language set to Java, the API can be imported and used as required. Here’s just some sample code to demonstrate that it works…

When running this JMeter project, the log viewer will display output generated. It is important to note that all code must be at the Java 1.4 language level, which means you can’t use lambdas, try-with-resources, for-each, etc. Just plain old Java code.


A quick disclaimer…

Although I put in a great effort into researching all the topics I cover, mistakes can happen.
If you spot something out of place, please do let me know.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle).
Use of any information contained in this blog post/article is subject to this disclaimer.

Other posts you may like…

Read More



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments