1

I've seen plenty of websites and stackoverflow pages on this subject, but none have my answer. My code below based on my pom.xml file, below, returns this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/jayway/jsonpath/Predicate at packagename.Hello.main(Hello.java:16)

My code file :

package packagename;

import java.util.List;

import com.jayway.jsonpath.Criteria;
import com.jayway.jsonpath.Filter;
import com.jayway.jsonpath.JsonPath;



public class SimValJSONTEST {
    public static void main(String[] args) {
        String json = "{\"id\":12345, \"studentname\":\"James Anderson\", \"age\":35,"
            + " \"subjects\":[\"Computer Science\", \"Physics\"]}";

        String subject = JsonPath.read(json, "$.subjects[0]");
        System.out.println(subject);
        
    }
}

My pom.xml have this dependencies in :

<!-- https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path -->
<dependency>
  <groupId>com.jayway.jsonpath</groupId>
  <artifactId>json-path</artifactId>
  <version>2.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path-assert -->
<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path-assert</artifactId>
    <version>2.7.0</version>
    <scope>test</scope>
</dependency>

What can i do ? Thanks in advance.

Jens
  • 67,715
  • 15
  • 98
  • 113
Remi
  • 11
  • 1
  • The code you wrote works for me, it outputs "Computer Science". Are you sure you're not using something from "assert"-package, but not running your code as test? If you remove "test" from your pom, does it work? Also, what IDE / java version are you using? – siggemannen Jan 25 '23 at 19:39

0 Answers0