前提:
elipse中的java建立一个项目,项目结构包括: 包名:com.test, 其中有一个java文件 beanShellPractice.java, java文件中有一个方法:calSquare
代码如下:
package com.test;
public class beanShellPractice {
public int calSquare(int i) {
int b;
b = i * i;
return b;
}
public static void main(String[] args) {
beanShellPractice beanShellPractice = new beanShellPractice();
System.out.println(beanShellPractice.calSquare(20));
}
}
1. jmeter中如何调用jar包
1)elipse中打包,下一步,下一步即可。
2)jmeter test plan首页,指定此jar的位置
3)beanshell中的代码如下:
import com.test.*;--- 引包,下面操作和java中调用某个方法完全一致
int x;
String y;
beanShellPractice beanShellPractice = new beanShellPractice();
x = beanShellPractice.calSquare(12);
y = String.valueOf(x);
System.out.println(y);
log.info("y="+y);
2. jmeter中如何调用java文件
只需要将调用jar包中的第一行,import com.test.* 替换为 source("C:/Mywork/100_ScrpitDev/EclipseWorkSpace/beanShell/src/com/test/beanShellPractice.java"); 用于指定java文件的位置
其他后续代码, 和调用jar包的完全相同
3. jmeter中如何调用class文件
在调用jar包方法中的第一行前面,再添加一行,addClassPath("C:/Mywork/100_ScrpitDev/EclipseWorkSpace/beanShell/bin/com/test/beanShellPractice.class"); 用于指定class文件的位置,
其他后续代码, 和调用jar包的完全相同