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

1

4

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 with --add-modules=jdk.incubator.httpclient. What can be done so that the code is executed via Eclipse?

Hydrothermal answered 16/7, 2017 at 13:58 Comment(4)
Does this help you : #44042198?Leicestershire
Yes. This helps. Thanks a lot for the lead :)Hydrothermal
@ Kavitha Karunakaran Please write an answer to your question, how did you adapt the answer in the given link for eclipse environment.Leicestershire
@Leicestershire Thanks for the suggestion. I've added my answer here.Hydrothermal
H
5

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.

enter image description here

After that, the code ran smoothly without throwing NoClassDefFoundError.

Hydrothermal answered 17/7, 2017 at 20:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.