【问题标题】:NoClassDefFoundError while trying to use jdk.incubator.http.HttpClient in java in Eclipse Oxygen [duplicate]尝试在 Eclipse Oxygen 中的 java 中使用 jdk.incubator.http.HttpClient 时出现 NoClassDefFoundError [重复]
【发布时间】:2017-07-16 13:58:49
【问题描述】:

这是我使用的代码 sn-p:

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。但是当我将--add-modules=jdk.incubator.httpclient 一起使用时,这个功能完美。有什么办法可以让代码通过 Eclipse 执行?

【问题讨论】:

  • 这对你有帮助吗:stackoverflow.com/questions/44041698/…?
  • 是的。这有帮助。非常感谢您的领导:)
  • @Kavitha Karunakaran 请写下您的问题的答案,您是如何在给定链接中针对 Eclipse 环境调整答案的。
  • @Steephen 感谢您的建议。我在这里添加了我的答案。

标签: jshell java eclipse http2 jshell java-http-client


【解决方案1】:

感谢@Steephen 在问题 cmets 中帮助我提示。查看here的答案后,我尝试在我的示例项目的运行配置中添加以下内容。

之后,代码运行流畅,没有抛出 NoClassDefFoundError。

【讨论】:

    猜你喜欢
    • 2011-12-22
    • 2013-08-19
    • 2021-09-28
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多