找不到org.apache.jmeter.testelement.TestIterationListene的类文件

时间:2018-12-09 14:57:28

标签: java maven jmeter

我遇到以下错误:

Error:(87, 20) java: cannot access org.apache.jmeter.testelement.TestIterationListener
  class file for org.apache.jmeter.testelement.TestIterationListener not found

我不知道为什么。这是有关有问题的代码的一些信息:

进口:

import org.apache.jmeter.assertions.ResponseAssertion;
import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.SetupThreadGroup;
import org.apache.jorphan.collections.HashTree;

导致此错误的函数:

private HTTPSampler createHttpSampler(String method, String host, int port, String path){
    HTTPSampler httpSampler = new HTTPSampler();
    httpSampler.setMethod(method);
    httpSampler.setDomain(host);
    httpSampler.setPort(port);
    httpSampler.setPath(path);
    return httpSampler;
}

我的Pom.xml中的J-Meter-Dependencies

        <!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_core -->
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_core</artifactId>
            <version>2.6</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_http -->
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_http</artifactId>
            <version>2.8</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_java -->
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_java</artifactId>
            <version>3.1</version>
        </dependency>

你们也许知道导致此问题的原因吗?有什么方法可以检查我必须添加哪个依赖项

org.apache.jmeter.testelement.TestIterationListener

1 个答案:

答案 0 :(得分:0)

当不同的JMeter库依赖于以某种方式发生冲突的不同依赖版本时,错误很可能是由所谓的jar hell引起的。

使用 3个不同版本的JMeter库是否有特定的原因?根据{{​​3}},您应该始终使用最新版本的JMeter,到目前为止,该版本是JMeter Best Practices,因此请考虑将依赖项修改为:

<dependency>
  <groupId>org.apache.jmeter</groupId>
  <artifactId>ApacheJMeter_core</artifactId>
  <version>5.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_http -->
<dependency>
  <groupId>org.apache.jmeter</groupId>
  <artifactId>ApacheJMeter_http</artifactId>
  <version>5.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_java -->
<dependency>
  <groupId>org.apache.jmeter</groupId>
  <artifactId>ApacheJMeter_java</artifactId>
  <version>5.0</version>
</dependency>

您还可以考虑在JMeter 5.0采样器创建中添加下一行:

httpSampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
httpSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());

这将允许您在JMeter GUI中打开生成的测试计划。