尝试在Eclipse Oxygen中的Java中使用jdk.incubator.http.HttpClient时出现NoClassDefFoundError [英] NoClassDefFoundError while trying to use jdk.incubator.http.HttpClient in java in Eclipse Oxygen

查看:178
本文介绍了尝试在Eclipse Oxygen中的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);

当我运行上述代码时,Eclipse为HttpClient抛出NoClassDefFoundError.但是,当我使用的问题并与.可以做什么才能通过Eclipse执行代码?

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆