JsonPath NoClassDefFoundError, or an alternative to JsonPath in Java
If You are using Maven or Gradle, just need to add this to your dependencies list:
For Maven projects:
In your Maven pom.xml file :
<dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <version>2.2.0</version> <scope>test</scope></dependency>
For Gradle projects:
In the dependencies section in your Gradle build.gradle file
testCompile 'com.jayway.jsonpath:json-path:2.2.0'
It should work
I think you have to add these dependencies to your project:https://code.google.com/p/json-path/downloads/detail?name=json-path-0.8.0-dependencies.zip&can=2&q=
In particular json-smart-1.1.jar where the missing Exception class is contained.
When there are conflicting versions of json-smart
, if the older version is picked which does not have the expected class.
How to fix
Verify the versions with mvn dependency:tree
.
Below, there's net.minidev:json-smart:jar:1.1.1:compile
and com.jayway.jsonpath:json-path:jar:1.1.0:test
which uses latest version of json-smart
.
$ mvn clean dependency:tree | grep json[INFO] +- net.logstash.log4j:jsonevent-layout:jar:1.7:compile[INFO] | +- net.minidev:json-smart:jar:1.1.1:compile[INFO] | +- io.spray:spray-json_2.11:jar:1.3.3:compile[INFO] | +- org.json:json:jar:20160810:compile[INFO] +- com.github.fge:json-schema-validator:jar:2.2.6:compile[INFO] | +- com.github.fge:json-schema-core:jar:1.2.5:compile[INFO] | | +- org.skyscreamer:jsonassert:jar:1.4.0:test[INFO] | | | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test[INFO] +- com.jayway.jsonpath:json-path:jar:1.1.0:test[INFO] | | | | +- io.gatling:jsonpath_2.10:jar:0.6.1:test[INFO] | | | | +- io.fastjson:boon:jar:0.28:test
So, exclude the older version of json-smart
from dependency as json-path
has latest version of json-smart
.
eg.
<dependency> <groupId>net.logstash.log4j</groupId> <artifactId>jsonevent-layout</artifactId> <version>1.7</version> <scope>compile</scope> <exclusions> <exclusion> <groupId>net.minidev</groupId> <artifactId>json-smart</artifactId> </exclusion> </exclusions> </dependency>