NoClassDefFoundError when trying to use jdk.incubator.http.HttpClient in java in Eclipse Oxygen

Here is the code snippet I'm using:

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 a NoClassDefFoundError for the HttpClient when I run the above code. But this works fine when I use jshell with --add --add-modules=jdk.incubator.httpclient . What can be done to make code run through Eclipse?

+3
source share
1 answer

Thanks to @ Steephen , who helped me with a hint in the comments on the question. After looking at the answers here , I tried adding the following to Run Configurations for my sample project.

enter image description here

After that, the code worked smoothly without throwing a NoClassDefFoundError.

+2
source

Source: https://habr.com/ru/post/1273613/


All Articles