NoClassDefFoundError while trying to use jdk.incubator.http.HttpClient in java in Eclipse Oxygen [duplicate]

丶灬走出姿态 提交于 2019-12-12 10:53:20

问题


Here is the code snippet that I use:

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 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?


回答1:


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.

After that, the code ran smoothly without throwing NoClassDefFoundError.



来源:https://stackoverflow.com/questions/45129397/noclassdeffounderror-while-trying-to-use-jdk-incubator-http-httpclient-in-java-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!