BeanShell引用jar包调用接口报错:Typed variable declaration : Method Invocation xxx

项目场景:

Jmeter接口自动化测试,因登录、设置密码等相关接口需要进行签名、请求数据需要利用算法进行加密处理,因此需要将相关实现封装成jar包,通过BeanShell调用jar包实现相关处理。


问题描述

java代码使用的是maven项目,因代码中用到了许多第三方库,在进行打包时需要将第三方包一起打包进jar包,对于java小白的我来说只能是在网上搜索一些pom.xml中需要的build相关配置,打包完成后通过BeanShell进行调用,报错如下:

2024-01-24 15:38:03,213 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval	Sourced file: inline evaluation of: ``import com.xxx.common.Login;  Map headers = new HashMap(); headers.put("xxx . . . '' : Typed variable declaration : Method Invocation Login.getVerifyCode
2024-01-24 15:38:03,213 WARN o.a.j.p.j.s.BeanShellSampler: Exception executing script. org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval	Sourced file: inline evaluation of: ``import com.xxx.common.Login;  Map headers = new HashMap(); headers.put("xxx . . . '' : Typed variable declaration : Method Invocation Login.getVerifyCode

BeanShell中代码实现

import com.xxx.common.Login;

Map headers = new HashMap();
headers.put("xxx","xxx");

String phone = "13271081234";
String url= "xxxxx/login/verify-code";
String code = Login.getVerifyCode(url,headers,phone);

log.info(code);

pom.xml中build相关配置

  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</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>3.6.0</version>
                <!--wy -->
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <!--wy -->
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

原因分析:

暂未找到具体原因,如果哪位朋友看见分享,可以留言告诉我问题原因,不胜感谢。


解决方案:

换了一种实现方式,不使用Maven,直接创建Java项目,Build system选择IntelliJ,将使用到的第三方库直接放在项目中自己创建的lib目录下,将该目录设置为Project Library,进行打包,然后在BeanShell中引用该jar,可以成功调用jar包中的接口。

  • 18
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值