首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >io/restassured/path/json/mapper/factory/JsonbObjectMapperFactory :java.lang.NoClassDefFoundError

io/restassured/path/json/mapper/factory/JsonbObjectMapperFactory :java.lang.NoClassDefFoundError
EN

Stack Overflow用户
提问于 2020-06-14 10:31:15
回答 1查看 5.3K关注 0票数 2

当使用restassured发出GET请求时,我的程序在以TestNg的形式运行时抛出以下错误

OutPut:

代码语言:javascript
运行
复制
java.lang.NoClassDefFoundError: io/restassured/path/json/mapper/factory/JsonbObjectMapperFactory
    at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
    at io.restassured.RestAssured.<clinit>(RestAssured.java:421)
    at SimpleGetTest.GetWeatherDetails(SimpleGetTest.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException: io.restassured.path.json.mapper.factory.JsonbObjectMapperFactory
    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)
    ... 28 more

我的java程序如下所示

SimpleGetTest.java

代码语言:javascript
运行
复制
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

public class SimpleGetTest {

    @Test
    public void GetWeatherDetails()
    {   
        // Specify the base URL to the RESTful web service
        RestAssured.baseURI = "http://restapi.demoqa.com/utilities/weather/city/";

        // Get the RequestSpecification of the request that you want to sent
        // to the server. The server is specified by the BaseURI that we have
        // specified in the above step.
        RequestSpecification httpRequest = RestAssured.given();

        // Make a request to the server by specifying the method Type and the method URL.
        // This will return the Response from the server. Store the response in a variable.
        Response response = httpRequest.request(Method.GET, "/Hyderabad");

        // Now let us print the body of the message to see what response
        // we have received from the server
        String responseBody = response.getBody().asString();
        System.out.println("Response Body is =>  " + responseBody);

    }

}

使用的外部jar:

  1. rest-assured-4.2.0
  2. json-path-4.0.0
  3. xml-path-4.0.0
  4. groovy-2.4.7
  5. commons-lang3-3.0
  6. httpmime-4.3.1
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-14 10:46:12

如果您使用的是4.2.0版本的rest-assured,那么您应该保留所有相关的JAR,比如相同版本的json-pathxml-path,以及

作为最佳实践,al使用了最新的jars,其中包含了大多数bug修复程序,看起来您现在需要使用最新版本的json-path。

代码语言:javascript
运行
复制
io.rest-assured:json-path:4.3.0
io.rest-assured:xml-path:4.3.0

还要确保运行时环境类路径包含那些JAR,并在编译时使用相同的版本。

编辑:

还包括

代码语言:javascript
运行
复制
io.rest-assured:rest-assured-common:4.3.0

下面是您所需的JAR列表

对于PKIX错误

如果-Djavax.net.ssl.trustStore存在于您的JVM参数中,Java将使用该参数指定的密钥存储库。您可以通过运行-Djavax.net.ssl.trustStore测试并指定相同的JVM参数来使用keystore来验证SSLPoke参数是否会导致问题。

例如:

代码语言:javascript
运行
复制
$JAVA_HOME/bin/java -Djavax.net.ssl.trustStore=/my/custom/truststore SSLPoke jira.example.com 443

您正在尝试访问一个安全的URL。因此,您需要首先在密钥存储库中导入公共证书。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62371283

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档