Three ways for Beanshell of jmeter Learning Guide to call java code
You can customize classes and methods in jmeter beanshell, and you can also call external existing java files, class files, and jar packages.
Here we will talk about calling external java files, class files, and jar packages respectively.
First, call java file
Syntax:
Source ("java file path")
The file path can be either absolute or relative.
Example:
Source ("E:\ eclipse\ workspace\ MD5\ src\ jmeter\ MD5.java")
Or:
Source ("MD5.java");-- the file is located in the jmeter bin directory
String strMd5 = MD5.GetMD5Code ("123456")
Second, call class file
Syntax:
AddClassPath ("directory where the class file is located")
Import class name
Example:
AddClassPath ("C:");-"can be a parent directory or an ancestor directory"
Import com.MD5
String strMd5 = MD5.GetMD5Code ("123456")
The path path of the imported class file is different from that of the imported java file. The comparison is as follows:
Source ("E:\ eclipse\ workspace\ MD5\ src\ jmeter\ MD5.java");-- you must specify the full path to the file when using an absolute path.
AddClassPath ("C:");-- the class file is fine as long as it is on disk C, not necessarily in the root directory of disk C. you don't have to specify the full path.
3. Call jar package
Usage:
Import the jar package in the test plan, or put the jar package in the jmeter lib directory ahead of time and restart it
Import class name
Example:
Import com.MD5
String strMd5 = MD5.GetMD5Code ("123456")