尝试在Eclipse Oxygen中的Java中使用jdk.incubator.http.HttpClient时出现NoClassDefFoundError
作者:互联网
这个问题已经在这里有了答案: > Java 9 no class definition exception 3个
这是我使用的代码片段:
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与–add-modules = jdk.incubator.httpclient一起使用时,此功能可以完美运行.怎样才能使代码通过Eclipse执行?
解决方法:
感谢@ Steephen,他帮助我在问题注释中提供了提示.查看答案here后,我尝试在示例项目的“运行配置”中添加以下内容.
此后,代码运行平稳,而不会抛出NoClassDefFoundError.
标签:jshell,eclipse,java-http-client,java,http2,jshell 来源: https://codeday.me/bug/20191111/2017926.html