To create a tool class method in a jar package used in JMeter

Source: Internet
Author: User

1. Create a new MAVEN project in idea.

2. Write Tool class methods, such as cryptographic algorithms. Here is an example of addition.

Package demotest;

public class DemoClass
{
public int Add (int a, int b) {
return a+b;
}

}

3. Configure in Maven to package the dependent packages to a fixed location.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The above 3 steps can be directly obtained
4. Execute the MVN package. Generate your own write jar packages and dependent jar packages.

5. Copy all jar packages from your project's jar package and the Lib directory to the JMeter Lib directory. (There may not be a third-party dependency package, depending on your project)

6. Download the latest JMeter package from JMeter website and unzip it. Paste the jar package for step 5th into the JMeter Lib directory.

https://jmeter.apache.org/download_jmeter.cgi

7. Double-click Jmeter.bat in the JMeter Bin directory to open JMeter.

8. Right-click on the test plan and add a thread group.

9. Right-click on the thread group and add a bean Shell Sampler.

10. Write the following code in the Script box and save the execution.

Import Demotest.democlass;

int sum = new DemoClass (). Add (2,6);

Vars.put ("Sum", sum.tostring ());

Log.info ("sum =" + sum);

11. You can also write Java code in the bean Shell preprocessor

First add an HTTP request

Add Bean Shell Preprocessor



To create a tool class method in the jar package used in JMeter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.