Jmeter 中调用自己编写 jar 中的类出错

自己编写 Java 类打 jar 包,并将 jar 包放置到 Jmeter/lib/ext/目录下,启动 Jmeter,并在 Jmeter 中编写脚本调用 jar 包中的类,执行脚本出现以下问题:

错误日志:

2017/01/12 17:29:17 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2017/01/12 17:29:17 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2017/01/12 17:29:17 INFO  - jmeter.testelement.TestPlan: add D:\Tool\Jmeter\apache-jmeter-3.0\lib\ext\uaastool.jar to classpath 
2017/01/12 17:29:17 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2017/01/12 17:29:17 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : getChallenge 
2017/01/12 17:29:17 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group getChallenge. 
2017/01/12 17:29:17 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
2017/01/12 17:29:17 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
2017/01/12 17:29:17 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2017/01/12 17:29:17 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2017/01/12 17:29:17 INFO  - jmeter.threads.JMeterThread: Thread started: getChallenge 1-1 
2017/01/12 17:29:17 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: `` String challenge = vars.get("challenge"); String response = com.uaastool.UaasTo . . . '' : Typed variable declaration : Class: com.uaastool.UaasTool.UaasTool not found in namespace 
2017/01/12 17:29:17 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: `` String challenge = vars.get("challenge"); String response = com.uaastool.UaasTo . . . '' : Typed variable declaration : Class: com.uaastool.UaasTool.UaasTool not found in namespace 
2017/01/12 17:29:17 INFO  - jmeter.threads.JMeterThread: Thread is done: getChallenge 1-1 
2017/01/12 17:29:17 INFO  - jmeter.threads.JMeterThread: Thread finished: getChallenge 1-1 
2017/01/12 17:29:17 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2017/01/12 17:29:17 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*) 
2017/01/12 17:30:09 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2017/01/12 17:30:09 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2017/01/12 17:30:09 INFO  - jmeter.testelement.TestPlan: add D:\Tool\Jmeter\apache-jmeter-3.0\lib\ext\uaastool.jar to classpath 
2017/01/12 17:30:09 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2017/01/12 17:30:09 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : getChallenge 
2017/01/12 17:30:09 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group getChallenge. 
2017/01/12 17:30:09 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
2017/01/12 17:30:09 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
2017/01/12 17:30:09 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2017/01/12 17:30:09 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2017/01/12 17:30:09 INFO  - jmeter.threads.JMeterThread: Thread started: getChallenge 1-1 
2017/01/12 17:30:09 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: `` String challenge = vars.get("challenge"); String response = com.uaastool.UaasTo . . . '' : Typed variable declaration : Class: com.uaastool.UaasTool.UaasTool not found in namespace 
2017/01/12 17:30:09 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: `` String challenge = vars.get("challenge"); String response = com.uaastool.UaasTo . . . '' : Typed variable declaration : Class: com.uaastool.UaasTool.UaasTool not found in namespace 
2017/01/12 17:30:09 INFO  - jmeter.threads.JMeterThread: Thread is done: getChallenge 1-1 
2017/01/12 17:30:09 INFO  - jmeter.threads.JMeterThread: Thread finished: getChallenge 1-1 
2017/01/12 17:30:09 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2017/01/12 17:30:09 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*) 

出现以上错误的原因:

解决方法:

这是我在使用 Jmeter 引入 jar 遇到过的问题,以及解决方案。欢迎交流,谢谢!


↙↙↙阅读原文可查看相关链接,并与作者交流