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