作者:小小小菜鸡 | 来源:互联网 | 2023-01-29 14:56
如何解决《尝试在EclipseOxygen中的Java中使用jdk.incubator.http.HttpClient时出现NoClassDefFoundError》经验,应该怎么办?
这是我使用的代码片段:
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://www.google.com")).GET().build();
HttpResponse.BodyHandler respOnseBodyHandler= HttpResponse.BodyHandler.asString();
HttpResponse respOnse= client.send(request, responseBodyHandler);
System.out.println("Status code = " + response.statusCode());
String body = response.body().toString();
System.out.println(body);
NoClassDefFoundError
当我运行上面的代码时,Eclipse抛出HttpClient。但是,当我将jshell与一起使用时,此功能可以完美运行--add-modules=jdk.incubator.httpclient
。怎样才能使代码通过Eclipse执行?