JMeter 未检测到添加到 lib 文件夹或类路径的 jar

JMeter not detecting jar added to lib folder or classpath

正在尝试通过 JMeter 查询 MongoDb。我已经从 maven 下载了 mongodb-driver-sync-4.2.3.jar 并将其复制到 liblib/ext 文件夹中。

我的 JSR223Sampler 代码基本上是 Mongo 的快速入门代码的复制粘贴:

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;

def connectionString = new ConnectionString("CONNECTION_STRING");
def settings = MongoClientSettings.builder()
        .applyConnectionString(connectionString)
        .build();
def mongoClient = MongoClients.create(settings);
def database = mongoClient.getDatabase("test");

但我一直收到错误消息,提示导入失败:

Script2.groovy: 1: unable to resolve class com.mongodb.ConnectionString
 @ line 1, column 1.
   import com.mongodb.ConnectionString;
   ^

Script2.groovy: 2: unable to resolve class com.mongodb.MongoClientSettings
 @ line 2, column 1.
   import com.mongodb.MongoClientSettings;
   ^

2 errors

javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 1: unable to resolve class com.mongodb.ConnectionString
 @ line 1, column 1.
   import com.mongodb.ConnectionString;
   ^

Script2.groovy: 2: unable to resolve class com.mongodb.MongoClientSettings
 @ line 2, column 1.
   import com.mongodb.MongoClientSettings;

我错过了什么?我该怎么做?

  1. lib/ext folder is for JMeter Plugins、MongoDB 驱动程序应该只转到“lib”文件夹
  2. 需要重新启动 JMeter 才能获取 .jar。
  3. mongodb-driver-sync-4.2.3.jar 本身不提供 com.mongodb.ConnectionString, the class lives in mongodb-driver-core-4.2.3.jar
  4. 根据您打开连接后要执行的操作,您可能还需要在 JMeter 类路径中包含 bson-4.2.3.jar

更多信息:MongoDB Performance Testing with JMeter