Home > OS >  Getting an error Exception in thread "main" java.lang.NoClassDefFoundError: Could not init
Getting an error Exception in thread "main" java.lang.NoClassDefFoundError: Could not init

Time:11-13

getting an error while executing the Rest Assured program

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
    at org.codehaus.groovy.runtime.dgmimpl.NumberNumberMetaMethod.<clinit>(NumberNumberMetaMethod.java:33)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
Response response = RestAssured.get("https://reqres.in/api/users/2");
Assert.assertEquals(response.getStatusCode(), 200);

Code Maven Dependency

CodePudding user response:

Add this dependency and remove all other rest assured dependencies. json-path is already included in rest-assured dependency.

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>5.2.0</version>
    <scope>test</scope>
</dependency>

If you need schema validator you can add:

<!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>5.2.0</version>
    <scope>test</scope>
</dependency>

Make sure you have JDK/JAVA_HOME env variable properly installed. The abouve depedencies should work with JDK 8

  • Related