如何将 jwt.io Java 库导入 JMeter
How do I import jwt.io Java library to JMeter
我正在尝试将 jjwt Java 库导入 JMeter,但出现以下错误;
ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223
Sampler, message: javax.script.ScriptException:
groovy.lang.MissingPropertyException: No such property: io for class:
Script4
我正在尝试使用 jjwt Java 库 https://github.com/jwtk/jjwt ... which can be found on the https://jwt.io/ 网站。我已将文件添加到 JMeter 类路径并使用 JSR223 采样器在 Groovy 中编写脚本...但它似乎不接受它。我猜这是因为它需要 .jar 文件,但库是 .java 文件,也许吧?
任何有关如何导入此 jjwt 库的理论将不胜感激。
这里还有一个post; How to generate JWT token on JMETER using a RSA 256 private key Required library or jar file? 讨论了此方法并表明它应该有效。
.java 文件是“文本”文件,它们也需要是 compiled into .class files before you can run them in JVM. You can download pre-built .jar from Maven Central (make sure to fetch all the dependencies),或者如果您更喜欢“硬”方式:
-
在某处创建一个名为 pom.xml 的文件,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>jwt</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId> <!-- or jjwt-gson if Gson is preferred -->
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.60</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
在终端应用程序中打开该文件夹
-
将 target/dependency
文件夹中的所有内容复制到 JMeter 安装的“lib”文件夹(或 JMeter Classpath 中的其他位置)
重启 JMeter
添加 JSR223 Sampler to your Test Plan and put your Groovy 使用 jjwt 库函数的代码。
我正在尝试将 jjwt Java 库导入 JMeter,但出现以下错误;
ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: io for class: Script4
我正在尝试使用 jjwt Java 库 https://github.com/jwtk/jjwt ... which can be found on the https://jwt.io/ 网站。我已将文件添加到 JMeter 类路径并使用 JSR223 采样器在 Groovy 中编写脚本...但它似乎不接受它。我猜这是因为它需要 .jar 文件,但库是 .java 文件,也许吧?
任何有关如何导入此 jjwt 库的理论将不胜感激。
这里还有一个post; How to generate JWT token on JMETER using a RSA 256 private key Required library or jar file? 讨论了此方法并表明它应该有效。
.java 文件是“文本”文件,它们也需要是 compiled into .class files before you can run them in JVM. You can download pre-built .jar from Maven Central (make sure to fetch all the dependencies),或者如果您更喜欢“硬”方式:
在某处创建一个名为 pom.xml 的文件,内容如下
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>jwt</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-api</artifactId> <version>0.11.2</version> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-impl</artifactId> <version>0.11.2</version> <scope>runtime</scope> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-jackson</artifactId> <!-- or jjwt-gson if Gson is preferred --> <version>0.11.2</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov-jdk15on</artifactId> <version>1.60</version> <scope>runtime</scope> </dependency> </dependencies> </project>
在终端应用程序中打开该文件夹
将
target/dependency
文件夹中的所有内容复制到 JMeter 安装的“lib”文件夹(或 JMeter Classpath 中的其他位置)重启 JMeter
添加 JSR223 Sampler to your Test Plan and put your Groovy 使用 jjwt 库函数的代码。