简体   繁体   中英

NoClassDefFoundError: io/restassured/RestAssured Error is occured

I have imported all the required jars to run RestAssured program. But facing this error.

import io.restassured.RestAssured;

import static io.restassured.RestAssured.*; public class bascis {

public static void main(String[] args) {
    // TODO Auto-generated method stub
        RestAssured.baseURI="https://rahulshettyacademy.com";
        given().log().all().queryParam("key", "qaclick123").header("Content-Type","application/json")
        .body("{\r\n"
                + "  \"location\": {\r\n"
                + "    \"lat\": -38.383494,\r\n"
                + "    \"lng\": 33.427362\r\n"
                + "  },\r\n"
                + "  \"accuracy\": 50,\r\n"
                + "  \"name\": \"Frontline house\",\r\n"
                + "  \"phone_number\": \"(+91) 983 893 3937\",\r\n"
                + "  \"address\": \"29, side layout, cohen 09\",\r\n"
                + "  \"types\": [\r\n"
                + "    \"shoe park\",\r\n"
                + "    \"shop\"\r\n"
                + "  ],\r\n"
                + "  \"website\": \"http://google.com\",\r\n"
                + "  \"language\": \"French-IN\"\r\n"
                + "}\r\n"
                + "\r\n"
                + "").when().post("maps/api/place/add/json").then().assertThat().statusCode(200);
}

}

enter image description here

Why not use maven to solve this dependency problem?, if you want you can use the following steps, its fairly easy.

  1. Create a maven project
  2. Add pom.xml at the root folder
  3. Add the following in your pom.xml for the rest assured dependency
<dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>4.4.0</version> <scope>test</scope> </dependency>
  1. After this run

mvn clean install

  1. Use the same program and run it.

The rest assured library was created to be used in the test scope. You shouldn't use it in main scope.

  • src
    • main
    • test <-- correct way

The rest assured library must be used in the test scope as explained here: The import io.restassured.RestAssured cannot be resolved

I recommend using gradle to manage dependencies. If you prefer, you can Download this project with the structure with main, test. In addition to gradle and JUnit support: https://github.com/developercancun/gradle-simple

git clone https://github.com/developercancun/gradle-simple.git

Run from the console in the project directory

./gradlew clean build

You can see that works here: https://imgur.com/a/GvNjFrn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM