zoukankan      html  css  js  c++  java
  • Jmeter——引入第三方jar包

    前言

    网上已经有写关于jmeter引入第三方jar包的文章,本文主要是记录遇到报错进行排查并解决的文章。

    编写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编译将依赖打包进去尝试一下。

        <build>
            <plugins>
                <plugin>
                    <groupId>org.scala-tools</groupId>
                    <artifactId>maven-scala-plugin</artifactId>
                    <version>2.15.2</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                                <goal>testCompile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    
                <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>
        </build>
    

    (4)再次在Bean shell使用show1()方法,并输出看看结果。

  • 相关阅读:
    百度的hao123.com篡改浏览器首页,解决办法
    图层叠加
    按日期统计数据,如何初始化一年的数据
    ORACLE的监听日志太大,客户端无法连接
    防火墙上开放Oracle服务端口1521的方法
    Java利用POI生成Excel强制换行
    poi jsp xls
    poi合并单元格同时导出excel
    使用CSS设置滚动条样式以及如何去掉滚动条的方法
    java环境变量的配置
  • 原文地址:https://www.cnblogs.com/se7enjean/p/15157644.html
Copyright © 2011-2022 走看看