使用lazerycode jmeter插件运行.jmx命令行时出现NoClassDefFoundError

时间:2018-02-12 03:01:58

标签: maven jmeter performance-testing jmeter-plugins jmeter-maven-plugin

我正在使用lazerycode jmeter maven plugin来执行我的jmeter测试。

当我尝试从UI运行我的jmx文件时,它运行得很好。

但是,当我尝试使用mvn时,

mvn clean install or mvn verify

它开始执行但是在我使用JSON提取器从响应中提取一些值时失败了。以下是我得到的错误,

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

这是我正在使用的POM:

<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>

以下是jmeter日志文件中的完整日志:

  

2018-02-11 18:44:20,835 INFO o.a.j.t.JMeterThread:线程完成:   Thread Group 1-1 2018-02-11 18:44:20,857 ERROR o.a.j.JMeter:Uncaught   异常: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]引起:   抛出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更多

我已按照here所述在pom.xml中添加了多个库,但问题仍未解决。

1 个答案:

答案 0 :(得分:1)

  1. 建议使用最新版本的JMeter,其Maven插件和JMeter插件,因此我建议修改 pom.xml ,如:

    <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. 这可能是Maven缓存的问题所以我建议使用-U键至少运行一次,如:

    mvn -U clean verify
    
  3. 如果您仍遇到问题,请使用-X键运行测试以启用完整调试输出并使用它更新您的问题(您可能还需要提供.jmx脚本)
  4. 更多信息:

    修改 谢谢Dmitri,这真的很有帮助。在我的情况下,我不得不在pom.xml中添加额外的库来解决此错误。

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

    我正在编辑这个答案,因为更多时候,人们不会通过评论来获得答案。