gpt4 book ai didi

java - 线程 "main"java.lang.NoClassDefFoundError : io/restassured/response/Response 中出现异常

转载 作者:行者123 更新时间:2023-12-01 16:46:32 27 4
gpt4 key购买 nike

用于登录 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 登录后调用获取响应的服务类。我只是使用 main 方法来检查响应。

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");
}

}

要发布的服务 URL。

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 文件中更改 rest-assured 的范围,因为根据您当前的配置,该依赖项仅在测试阶段可用。

尝试将其更改为

<scope>compile</scope>

关于java - 线程 "main"java.lang.NoClassDefFoundError : io/restassured/response/Response 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49489317/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com