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?