简体   繁体   中英

beanshell sampler, i want access java code from jmeter

I have stuck with below error in jmeter .

Response code: 500 Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of'

bean shell code:

import tools.JmeterTools; 

JmeterTools jt = new JmeterTools();  

int num = Integer.parseInt(vars.get("A1"));

num = jt.randInt(num);  

vars.put("A1", num.toString());  

num =  Integer.parseInt(vars.get("B1")); 

num = jt.sqrInt(num);   

vars.put("B1", num.toString());  

vars.put("B2", jt.sqrstr(vars.get("B2")));  

}

eclipse code:

package tools;
import java.util.Random;

public class JmeterTools {

    public JmeterTools(){
    }

    public int randInt (int x){
        Random randomGenerator= new Random();
        return randomGenerator.nextInt(x);
    }

    public int sqrInt(int x){
        return x*x;
    }

    public String sqrstr(String x){
        int y= Integer.parseInt(x);
        return String.valueOf(y*y);
    }

}

Did you:

  • export your JmeterTools class as a JAR
  • Is the JAR OK ?
  • put the JAR in jmeter/lib folder ?

Also, you have a } at end of your beanshell code that shouldn't be there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM