当前位置:网站首页>JMeter/IDEA中引用jar包json-path.jar的坎坷之路
JMeter/IDEA中引用jar包json-path.jar的坎坷之路
2022-07-26 00:28:00 【测试超有范】
在讲JMeter中引入的错误之前,先讲IDEA中引入json-path-xxx.jar错误的问题
如图,在项目中引入json-path包。

FileInputStream fis = new FileInputStream(file);
Map<String, Object> loaded = (Map<String, Object>) yaml.load(fis);
String header_str = new JSONObject(loaded).toString();
String data = JsonPath.read(header_str,"$.sit.adminun");执行时提示:
Exception in thread "main" java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI
at com.jayway.jsonpath.internal.DefaultsImpl.<init>(DefaultsImpl.java:17)
at com.jayway.jsonpath.internal.DefaultsImpl.<clinit>(DefaultsImpl.java:15)
at com.jayway.jsonpath.Configuration.getEffectiveDefaults(Configuration.java:43)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:168)
at com.jayway.jsonpath.internal.ParseContextImpl.<init>(ParseContextImpl.java:21)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:550)
at com.functions.ReadYaml.main(ReadYaml.java:33)
Caused by: java.lang.ClassNotFoundException: net.minidev.json.writer.JsonReaderI
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
原因,如同网上所说,缺少相关依赖包!!!
因为我们是通过静态把包放到项目里,看不出json-path依赖了包,但是当通过Maven下载时,就发现带着下载了其他好几个包!!!再运行就没问题了~~(PS:把相关依赖包都静态引入也可以的)
初步结论,看来单纯引用json-path会报错,需要加依赖包。接下来,在讲下JMeter单纯通过引入 json-path包报错的问题。
JMeter引入报错
JMeter中问题描述:
1、在jmeter中使用beanshell脚本时,使用 json-path-xxxxx.jar 解析json数据时会报错:Error in method invocation: Static method read( java.lang.String, java.lang.String ) not found in class'com.jayway.jsonpath.JsonPath。
import com.jayway.jsonpath.JsonPath;
String s = prev.getResponseDataAsString();
String res = JsonPath.read(s,"$..idcard").toString();
log.info("-------------"+res);具体报错:
2022-07-25 21:14:58,749 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import com.jayway.jsonpath.JsonPath; String s = prev.getResponseDataAsString(); . . . '' : Typed variable declaration : Error in method invocation: Static method read( java.lang.String, java.lang.String ) not found in class'com.jayway.jsonpath.JsonPath'
2022-07-25 21:14:58,749 WARN o.a.j.e.BeanShellPostProcessor: Problem in BeanShell script: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import com.jayway.jsonpath.JsonPath; String s = prev.getResponseDataAsString(); . . . '' : Typed variable declaration : Error in method invocation: Static method read( java.lang.String, java.lang.String ) not found in class'com.jayway.jsonpath.JsonPath'
解决方案:
方案1:既然idea中有简单验证是缺少依赖包,那咱们就给他添加依赖包,然后发现,这些依赖包在lib目录下都有!!!!结果还是行不通!!
方案2:编写代码,代码思路:类JsonUtil中的方法ParaseJson封装read方法,第一个参数是json字符串,第二个参数是jsonpath,将代码导出为jar包,包放入路径\apache-jmeter-5.0\lib\ext 。
import com.jayway.jsonpath.JsonPath;
public class JsonUtil {
public String ParaseJson(String str,String paras){
String res = JsonPath.read(str,paras).toString();
return res;
}
}这个解决方案的来源:jmeter下解决:beanshell 使用jsonpath解析json报错
作者百度网盘 jmeterUtil.jar,提取码:o0fr
最后:
讲真,JMeter中中还是没搞懂这个问题根源。。。有明白的大佬请求赐教~
参考:jmeter中引用jar包jsonpath的坎坷之路: - 走看看
边栏推荐
- 数据流通交易场景下数据质量综合管理体系与技术框架研究
- Wechat applet for loop
- IP Core: PLL
- 二进制表示--2的幂
- Nodejs learning resources
- Redis killed twelve questions. How many questions can you carry?
- 【oops-framework】随机数生成管理
- Understanding of "dof: a demand oriented framework for imagedenoising"
- Pikachu target clearance and source code analysis
- 8种MySQL常见SQL错误用法,我全中
猜你喜欢

Hcip - republish

实战演练 | 查找在给定时间范围内购买超过 N 件商品的客户

hyperf使用之curd

数据流通交易场景下数据质量综合管理体系与技术框架研究

Find the single dog (Li Kou 260)

Research progress of data traceability based on the perspective of data element circulation

YOLOV3

SQL time splicing problem, splicing recovery automatically truncated by the system

letfaw

白蛋白纳米-超声微泡载组织型纤溶酶原激活物基因靶向制备研究
随机推荐
HOOPS Exchange助力混合计算流体动力学软件搭建3D格式导入读取功能 | 客户案例
使用LocalDate类完成日历设计
[contents] mqtt, nodejs projects
解决背景图设置100%铺满时,缩放浏览器出现水平滚动条时,滚动条超出的部分背景图没有铺满的问题
Hcip - republish
攻防世界web题-favorit_number
Understanding of "dof: a demand oriented framework for imagedenoising"
Pikachu靶机通关和源码分析
mysql事务的四大特性以及隔离级别
白蛋白纳米-超声微泡载组织型纤溶酶原激活物基因靶向制备研究
Tid-mop: a comprehensive framework for security management and control under the scenario of data exchange
Leetcode 笔记 350. 两个数组的交集 II
Tarjan finds the strongly connected component o (n+m), shrinking point
二进制表示--2的幂
Applet page generation link sent by SMS
ShardingSphere数据分片
基于SEIR模型的网络医疗众筹传播建模与仿真分析
Markdown writing platform
Appium combs the process from start to test and then to end
MWEC:一种基于多语义词向量的中文新词发现方法