簡體   English   中英

線程“ main”中的異常java.lang.NoClassDefFoundError:io / restassured / response / Response

[英]Exception in thread “main” java.lang.NoClassDefFoundError: io/restassured/response/Response

用於登錄到Jira localhost的POJO類。

 package com.rest.requestpojo; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; public class LoginApi { @SerializedName("username") @Expose private String username; @SerializedName("password") @Expose private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } 

服務類,以從JIRA呼叫后獲得響應以進行登錄。 我只是使用主要方法來檢查響應。

 package com.rest.services; import org.json.JSONObject; import com.rest.requestpojo.LoginApi; import io.restassured.RestAssured; import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; public class Service { public Response jiraLoginAuth(String username, String password) { LoginApi login = new LoginApi(); login.setUsername(username); login.setPassword(password); JSONObject jsonObject = new JSONObject(login); RequestSpecification requestSpecification = RestAssured.given(); requestSpecification.contentType("application/json"); requestSpecification.body(jsonObject); Response response =requestSpecification.post(ServiceURL.jiraLoginUrl); System.out.println(response); return response; } public static void main(String[] args) { Service service = new Service(); service.jiraLoginAuth("chinmaya","ck2016d"); } } 

要發布的服務網址。

 package com.rest.services; public class ServiceURL { public final static String jiraLoginUrl ="http://localhost:8080/rest/auth/1/session"; } 

以下是POM.XML頁,其中提供了所有依賴項。

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.restAPIFramework</groupId> <artifactId>restAPIFramework</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>3.0.7</version> <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>json-schema-validator</artifactId> <version>3.0.7</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20180130</version> </dependency> </dependencies> </project> 

以下是我在運行時遇到的錯誤。 在POM中是否缺少任何依賴項或jar導致問題? 請幫我解決這個問題,我是新手。

 Exception in thread "main" java.lang.NoClassDefFoundError: io/restassured/response/Response at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetMethodRecursive(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.validateMainClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException: io.restassured.response.Response at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) 

您需要更改pom文件中的保證范圍,因為根據當前配置,依賴性僅在測試階段可用。

嘗試將其更改為

<scope>compile</scope>

將我放心的依賴版本從3.0.0更改為3.0.7為我解決了這個問題。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM