maven - Jmeter with maven and using external groovy scripts issues with groovy imports
问题描述
I'd like to execute jmeter tests from maven using groovy scripts, but I got the error below. For setting up jmeter and maven I did what is described here.
Shall I package my groovy functions and entities into a jar and copy into jmeter's lib directory and only put those groovy scripts next to the jmx file which contains the sampler code?
2019-06-22 17:40:17,714 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true
2019-06-22 17:40:17,714 INFO o.a.j.s.SampleResult: sampleresult.nanoThreadSleep=5000
2019-06-22 17:40:17,744 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script CreateUsers, message: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script4.groovy: 4: unable to resolve class com.google.gson.Gson
@ line 4, column 1.
import com.google.gson.Gson;
^
解决方案
我找到了答案:
- 我需要将我想在测试中使用的库打包到 jar 中并将它们放入
jmeter/lib
目录中 - 我必须对齐 Sampler 脚本路径,以便 jmeter 可以使用它们
第一个解决方案来自jmeter-maven-plugin doc:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>USE LAST VERSION</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</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>
第二个解决方案是我需要在 jmx 文件旁边复制 Sampler 脚本。Maven 可以使用maven-resource-plugin轻松做到这一点。
推荐阅读
- julia - 使用 ./startup.jl 文件设置 nprocs()
- oracle - 未找到 Oracle 客户端和网络组件。源 Oracle 数据库 SO AIX
- swift - 过早调用完成处理程序
- reactjs - Chrome 开发者工具显示 JSON 对象的不同值
- r - 如何在 tmap 中指定多面板布局两侧的标签?
- twilio - 无法从 Twilio Studio 创建任务
- java - 错误:对重载定义的模糊引用,Scala 中的 ND4J
- python - Python for Maya - 滑块换色器
- java - 获取请求适用于 POSTMAN,但在我的 Java 应用程序中引发垃圾响应
- tsql - 如何在 Sql server 中使用作业计划运行顺序作业