Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Three ways for Beanshell of jmeter Learning Guide to call java code

Shulou Source: shulou.com Published: 2022-06-03 04:57:47 10月02日 Update

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")

Tags: File path directory example class name syntax different not used location method ancestor root guide test code learning guide guide way learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno vpn Linux MariaDB