Skip to content

Adding Excluding libraries to from the classpath

Vincent DABURON edited this page Aug 11, 2025 · 7 revisions

Adding jar's to the /lib directory

You can add any additional Java libraries to JMeter's lib/ directory by using the <testPlanLibraries> configuration element. This uses the Eclipse Aether libraries to perform dependency resolution.

<project>
    [...]
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>3.6.0</version>
                    <executions>
                        <!-- Generate JMeter configuration -->
                        <execution>
                            <id>configuration</id>
                            <goals>
                                <goal>configure</goal>
                            </goals>
                        </execution>
                        <!-- Run JMeter tests -->
                        <execution>
                            <id>jmeter-tests</id>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                        </execution>
                        <!-- Fail build on errors in test -->
                        <execution>
                            <id>jmeter-check-results</id>
                            <goals>
                                <goal>results</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <testPlanLibraries>
                             <artifact>org.apache.activemq:activemq-spring:5.15.2</artifact>
			     <artifact>org.apache.activemq:activemq-client:5.15.2</artifact>
			     <artifact>org.apache.activemq:activemq-broker:5.15.2</artifact>
		        </testPlanLibraries>
                        <excludedArtifacts>
                             <exclusion>com.sun.jdmk:jmxtools</exclusion>
                             <exclusion>com.sun.jmx:jmxri</exclusion>
			</excludedArtifacts>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>

Adding jar's to the /lib/ext directory

You can add any additional Java libraries to JMeter's lib/ext directory by using the <jmeterExtensions> configuration element. This uses the Eclipse Aether libraries to perform dependency resolution.

<project>
    [...]
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>3.6.0</version>
                    <executions>
                        <!-- Generate JMeter configuration -->
                        <execution>
                            <id>configuration</id>
                            <goals>
                                <goal>configure</goal>
                            </goals>
                        </execution>
                        <!-- Run JMeter tests -->
                        <execution>
                            <id>jmeter-tests</id>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                        </execution>
                        <!-- Fail build on errors in test -->
                        <execution>
                            <id>jmeter-check-results</id>
                            <goals>
                                <goal>results</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <jmeterExtensions>
                            <artifact>kg.apc:jmeter-plugins-casutg:2.4</artifact>
                        </jmeterExtensions>
                        <!-- The plugin uses some broken dependencies 
                             An alternative is to set this to true and use excludedArtifacts, see below
                        -->
                        <downloadExtensionDependencies>false</downloadExtensionDependencies>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>

Adding jar's to the /lib/junit directory

You can add any additional Java libraries to JMeter's lib/junit directory by using the <junitLibraries> configuration element. This uses the Eclipse Aether libraries to perform dependency resolution.

<project>
    [...]
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>3.6.0</version>
                    <executions>
                        <!-- Generate JMeter configuration -->
                        <execution>
                            <id>configuration</id>
                            <goals>
                                <goal>configure</goal>
                            </goals>
                        </execution>
                        <!-- Run JMeter tests -->
                        <execution>
                            <id>jmeter-tests</id>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                        </execution>
                        <!-- Fail build on errors in test -->
                        <execution>
                            <id>jmeter-check-results</id>
                            <goals>
                                <goal>results</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <junitLibraries>
                            <artifact>com.lazerycode.junit:junit-test:1.0.0</artifact>
                        </junitLibraries>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>

Excluding a jar from classpath to fix jar conflict

You may face issues with some broken dependencies of a used extension. To fix it you can use excludedArtifacts tag:

<project>
    [...]
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>3.6.0</version>
                    <executions>
                        <!-- Generate JMeter configuration -->
                        <execution>
                            <id>configuration</id>
                            <goals>
                                <goal>configure</goal>
                            </goals>
                        </execution>
                        <!-- Run JMeter tests -->
                        <execution>
                            <id>jmeter-tests</id>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                        </execution>
                        <!-- Fail build on errors in test -->
                        <execution>
                            <id>jmeter-check-results</id>
                            <goals>
                                <goal>results</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <excludedArtifacts>
                             <exclusion>commons-pool2:commons-pool2</exclusion>
                             <exclusion>commons-math3:commons-math3</exclusion>
                             <exclusion>org.slf4j:slf4j-nop</exclusion>
                             <exclusion>logkit:logkit</exclusion>
                             <exclusion>avalon-logkit:avalon-logkit</exclusion>
                             <exclusion>jdom:jdom</exclusion>
                             <exclusion>log4j:log4j</exclusion>
                             <exclusion>commons-logging:commons-logging</exclusion>
                             <exclusion>excalibur-logger:excalibur-logger</exclusion>
                        </excludedArtifacts>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>

Adding jar NOT in a MAVEN repo to the new /lib directory and declare the relative path in "Test Plan"

If you add a library NOT in a MAVEN repo, you could declare the relative path to your library in the JMeter script > Test Plan > Add a directory or jar to classpath.

Put the library in the directory e.g:src/test/jmeter/lib/my-lib-1.0.jar (create a new sub directory lib to put your library)
When the JMeter maven plugin will start, it create a new directory for Apache JMeter
E.g: user.dir=target/fbe2d80a-6e9f-406a-a0bc-4fb5d070fde7/jmeter/bin
And all files and sub directories in the src/test/jmeter will be copied in target/jmeter/testsFiles
so the library will be target/jmeter/testFiles/lib/my-lib-1.0.jar => in the no standard lib directory.
The relative path to declare at "Test Plan > Add a directory or jar to classpath" is
../../../jmeter/testFiles/lib/my-lib-1.0.jar

Without "JMeter Maven Plugin" directly in JMeter, if you want to test code that call function in your library the easiest way is to add the library in <JMETER_HOME>/lib (my-lib-v1.0.jar) and when all is ok, copy the library my-lib-v1.0.jar in the maven standard directory src/test/jmeter or add a new sub directory lib src/test/jmeter/lib

Clone this wiki locally