3

我正在尝试编写一个模拟,我希望能够运行模拟。尝试 $mvn gatling:execute 时出现错误。

我的 pom 具有以下依赖项:

<dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-charts</artifactId>
    <version>2.2.5</version>
</dependency>
<dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-core</artifactId>
    <version>2.2.5</version>
</dependency>

和以下插件:

<build>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <scalaVersion>2.12.3</scalaVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-maven-plugin</artifactId>
            <version>2.2.4</version>
            <executions>
                <execution>
                    <id>performanceTests</id>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <simulationClass>simulations.SimulationClass</simulationClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是我遇到的错误:

12:50:36.313 [main][WARN ][ZincCompiler.scala:141] i.g.c.ZincCompiler$ - 
Pruning sources from previous analysis, due to incompatible CompileSetup.
java.lang.ClassNotFoundException: io.gatling.app.Gatling
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:42)
    at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)

包含的依赖:

<dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-app</artifactId>
    <version>2.2.5</version>
</dependency>

但现在我得到一个新错误:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
Caused by: java.lang.NoSuchMethodError: scala.Product.$init$(Lscala/Product;)V
at com.github.mnogu.gatling.mqtt.protocol.MqttProtocolOptionPart.<init>(MqttProtocol.scala:124)
at com.github.mnogu.gatling.mqtt.protocol.MqttProtocol$.apply(MqttProtocol.scala:24)
at com.github.mnogu.gatling.mqtt.protocol.MqttProtocolBuilder$.apply(MqttProtocolBuilder.scala:13)
at com.github.mnogu.gatling.mqtt.Predef$.mqtt(Predef.scala:9)
at simulations.SimulationClass.<init>(SimulationClass.scala:10)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at io.gatling.app.Runner.run0(Runner.scala:79)
at io.gatling.app.Runner.run(Runner.scala:64)
at io.gatling.app.Gatling$.start(Gatling.scala:59)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:43)
at io.gatling.app.Gatling$.main(Gatling.scala:35)
at io.gatling.app.Gatling.main(Gatling.scala)

...

关于这个问题的任何线索都会有很大帮助。

谢谢

4

2 回答 2

1

您的错误表明您缺少以下依赖项,

<!-- https://mvnrepository.com/artifact/io.gatling/gatling-app -->
<dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-app</artifactId>
    <version>2.2.5</version>
</dependency>

更新

您的第二个错误主要是因为您的代码在运行时引用的 jar 文件与编译时使用的 jar 文件不同。因此,请确保在编译和运行时使用相同的 jar。

为此,您可以删除依赖的 jar 文件,maven 清理您的项目并重新编译并运行该程序。

于 2017-10-16T10:53:02.170 回答
1

看起来我使用的外部 jar 仅与 gatling core 2.2.3 兼容。将 gatling 核心版本恢复到 2.2.3 并将 scala 版本恢复到 2.11.8 解决了这个问题。

这是我的 pom 现在的样子:

<dependency>
        <groupId>io.gatling.highcharts</groupId>
        <artifactId>gatling-charts-highcharts</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-core</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-app</artifactId>
        <version>2.2.3</version>
    </dependency>

<plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <scalaVersion>2.11.8</scalaVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-maven-plugin</artifactId>
            <version>2.2.3</version>
            <executions>
                <execution>
                    <id>performanceTests</id>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <simulationClass>simulations.SimulationClass</simulationClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins> 
于 2017-10-20T09:42:16.970 回答