0
votes

I am using lazerycode jmeter maven plugin to execute my jmeter tests.

When I try to run my jmx file from the UI, it runs perfectly fine.

but, when I try with to do with mvn,

mvn clean install or mvn verify

It starts executing but it fails at a point where I have used the JSON extractor to extract some values from response. Below is the error I get,

[INFO] Uncaught Exception java.lang.NoClassDefFoundError: com/jayway/jsonpath/internal/JsonReader. See log file for details.

This is the POM that I am using:

<build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.6.0</version>
                <configuration>
                    <testResultsTimestamp>false</testResultsTimestamp>
                    <propertiesUser>
                        <!-- Some user properties here -->
                    </propertiesUser>

                    <jmeterExtensions>
                        <artifact>kg.apc:jmeter-plugins-manager:0.19</artifact>
                        <artifact>Kg.apc:jmeter-plugins-extras-libs:1.3.1</artifact>
                        <artifact>kg.apc:jmeter-plugins-json:jar:2.3</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>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>kg.apc</groupId>
                        <artifactId>jmeter-plugins-extras-libs</artifactId>
                        <version>1.3.1</version>
                    </dependency>

                </dependencies>
            </plugin>
        </plugins>
    </build>

Below is the complete logs from the jmeter log file:

2018-02-11 18:44:20,835 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1 2018-02-11 18:44:20,857 ERROR o.a.j.JMeter: Uncaught exception: java.lang.NoClassDefFoundError: com/jayway/jsonpath/internal/JsonReader at com.atlantbh.jmeter.plugins.jsonutils.jsonpathextractor.JSONPathExtractor.process(JSONPathExtractor.java:102) ~[jmeter-plugins-extras-libs-1.3.1.jar:?] at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:833) ~[ApacheJMeter_core-3.3.jar:3.3 r1808647] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:524) ~[ApacheJMeter_core-3.3.jar:3.3 r1808647] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:424) ~[ApacheJMeter_core-3.3.jar:3.3 r1808647] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:255) ~[ApacheJMeter_core-3.3.jar:3.3 r1808647] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151] Caused by: java.lang.ClassNotFoundException: com.jayway.jsonpath.internal.JsonReader at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_151] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_151] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_151] ... 6 more

I have added multiple libraries in the pom.xml as described here but the problem is not resolved.

1

1 Answers

1
votes
  1. It is recommended to use latest versions of JMeter, its Maven plugin and JMeter Plugins so I would recommend amending your pom.xml like:

    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.example</groupId>
        <artifactId>mvn-jmeter</artifactId>
        <version>1.0-SNAPSHOT</version>
        <name>maven-jmeter-demo</name>
        <url>http://maven.apache.org</url>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>2.7.0</version>
                    <executions>
                        <execution>
                            <id>jmeter-tests</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <jmeterExtensions>
                            <artifact>kg.apc:jmeter-plugins-json:jar:2.6</artifact>
                            <artifact>kg.apc:jmeter-plugins-manager:0.19</artifact>
                            <artifact>kg.apc:jmeter-plugins-extras-libs:1.4.0</artifact>
                        </jmeterExtensions>
                        <downloadExtensionDependencies>false</downloadExtensionDependencies>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    
  2. It might be an issue with Maven caches so I would suggest running it at least once with -U key like:

    mvn -U clean verify
    
  3. If you still experience problems run your test with -X key to enable full debugging output and update your question with it (you might also need to provide your .jmx script)

More information:

EDIT: Thanks Dmitri, this was really helpful. In my case I had to add additional library in the pom.xml to resolve this error.

<artifact>com.jayway.jsonpath:json-path:2.2.0</artifact>

I am editing this answer because more often, people don't look into comments to get the answer.