尝试在Eclipse Oxygen中的Java中使用jdk.incubator.http.HttpClient时出现NoClassDefFoundError [英] NoClassDefFoundError while trying to use jdk.incubator.http.HttpClient in java in Eclipse Oxygen
问题描述
这是我使用的代码段:
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);
当我运行上述代码时,Eclipse为HttpClient抛出NoClassDefFoundError
.但是,当我使用 jshell 的问题并与
Eclipse throws NoClassDefFoundError
for HttpClient when I run the above code. But this functions perfectly when I use jshell with --add-modules=jdk.incubator.httpclient
. What can be done so that the code is executed via Eclipse?
推荐答案
感谢@ Steephen 帮了我一个忙.在问题注释中提示.在此处查看答案之后,我尝试在运行配置"中添加以下内容示例项目.
Thanks to @Steephen who helped me with a hint in the question comments. After viewing the answers here, I tried adding the following in Run Configurations for my sample project.
此后,代码运行平稳,而不会抛出NoClassDefFoundError.
After that, the code ran smoothly without throwing NoClassDefFoundError.
这篇关于尝试在Eclipse Oxygen中的Java中使用jdk.incubator.http.HttpClient时出现NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!