我是Jmeter工具的新手,我正在尝试使用自己的java类来调用BeanShell预处理器中的函数。 我编写了一个Java程序并将其打包成.jar文件并将其复制到安装了Jmeter的/ lib / ext文件夹中。 这是我的java类片段:
package cacreator;
import java.util.Scanner;
public class CaCreator {
static String Name = "\"Name\" : 11";
static String AppName = "\"ApplicationGroup\" : \"qa\"";
static String caValues = ""; // = "[{";
public static String createCa(int count)
{
for (int vCount = 1; vCount <= count; vCount++) {
caValues = caValues.concat( "\n" + "{ \n" + Name + ", \n\"Value\" : \"" + vCount+300 + "\",\n" + AppName + "\n}");
if(vCount != count)
{
caValues = caValues.concat(",");
// caValues = caValues.concat("\"Name\" : \"Test");
}
}
return caValues;
}
和BeanShell预处理器的代码:
import cacreator.CaCreator;
CaCreator obj1 = new CaCreator();
int firstParam = Integer.parseInt(bsh.args[0]);
String outPut = obj1.createCa(firstParam);
vars.put("ca", outPut);
我收到以下错误:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import cacreator.CaCreator; CaCreator obj1 = new CaCreator(); int firstParam = I . . . '' : Typed variable declaration : Error in method invocation: Method createCa( int ) not found in class'cacreator.CaCreator'
WARN - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import cacreator.CaCreator; CaCreator obj1 = new CaCreator(); int firstParam = I . . . '' : Typed variable declaration : Error in method invocation: Method createCa( int ) not found in class'cacreator.CaCreator'
提前致谢!
答案 0 :(得分:0)
您需要将jar放在jmeter / lib文件夹中,而不是jmeter / lib / ext中。
此外,由于您的方法是静态的,因此您可以通过以下方式简化代码:
import cacreator.CaCreator;
int firstParam = Integer.parseInt(bsh.args[0]);
String outPut = CaCreator.createCa(firstParam);
vars.put("ca", outPut);