Jmeter -jsr 223-外部库出错
我的java代码导入org.web3j,按预期运行,没有错误
package test;
import java.nio.charset.StandardCharsets;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.Sign;
import org.web3j.utils.Numeric;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String privateAccountKey = "privateAccountKey ";
Credentials credentials = Credentials.create(privateAccountKey);
String message="messageABC";
byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
Sign.SignatureData signature = Sign.signPrefixedMessage(messageBytes, credentials.getEcKeyPair());
byte[] value = new byte[65];
System.arraycopy(signature.getR(), 0, value, 0, 32);
System.arraycopy(signature.getS(), 0, value, 32, 32);
System.arraycopy(signature.getV(), 0, value, 64, 1);
System.out.println("signature: " + Numeric.toHexString(value));
}
}
在jmeter中,我使用JSR 223后处理器
我已经将core-5.0.0.jar添加到文件夹apache-jmeter-5.5\lib\ext(从https://mvnrepository.com/artifact/org.web3j/core/5.0.0下载)并重新启动jmeter
运行后,错误显示为javax.script.ScriptException:来源文件:内联评估:import java.nio.charset.StandardCharsets; import org.web3j.crypto.Credentials; i . . . '' : Typed variable declaration : Class: Credentials not found in namespace : at Line: 7 : in file: inline evaluation of:
导入java.nio.charset. standard字符集;导入. web3j.crypto.Credentials;我. . . ..."“:行内评价中的凭证:'导入java.nio.charset.standardCharsets;导入. web3j.crypto.Credentials; i . . .第7行的“”
请指教多谢
1条答案
按热度按时间mnowg1ta1#
1.您应该将任何第三方.jar库放置到lib文件夹中。lib/ext用于JMeter插件。有关详细信息,请参阅JMeter类路径用户手册条目。
org.web3j.core
库不包含org.web3j.crypto.Credentials
类,您需要将this library添加到JMeter的lib文件夹中1.由于JMeter3.1您应该使用Groovy语言编写脚本,尤其是在涉及资源密集型加密操作时,请参见Beanshell vs. JSR223 vs. Java For JMeter: Complete Showdown以了解更多详细信息,因此请考虑将语言切换为
groovy
,因为java
不是真实的的Java,它是Beanshell解释器