前言
网上已经有写关于JMeter引入第三方jar包的文章,本文主要是记录遇到报错进行排查并解决的文章。
编写Java类
编写Java类并实现两个方法。一个方法需要用到第三方jar包,在这用maven作引用:
maven编译打包
JMeter引入jar包
尝试在bean-shell预处理程序中使用我们的Java类。
处理jmeter-bean-shell异常
Error invoking bsh method:eval Sourced file inline evaluation of.
(1)我们尝试调用testcase类中的show方法看看。
(2)通过上一步,发现是可以调用到方法的,那么我们去代码看看是因为什么问题。
(3)通过分析,可以想到是因为引用了第三方Jar包,maven编译时并没有将依赖的jar包引入,导致JMeter找不到对应的jar包。
那么我们可以通过maven编译将依赖打包进去尝试一下。
org.scala-tools maven-scala-plugin 2.15.2 compile testCompile <plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<!--这里写上TestCase的类路径,如果写入无效,在TestCase类中增加一个main方法 -->
<mainClass>com.develop.TestCase</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<defaultGoal>compile</defaultGoal>
(4)再次在Bean shell使用show1()方法,并输出看看结果。
资源分享
最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走…
这些资料,对于想从事【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助…….