2017-07-16 442 views
3

这里使用jdk.incubator.http.HttpClient在Java中,我使用的代码片段:NoClassDefFoundError的,而试图在Eclipse中氧气

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抛出NoClassDefFoundError为HttpClient的,当我运行上面的代码。但是,当我使用--add-modules=jdk.incubator.httpclient时,此功能完美。可以做些什么以便通过Eclipse执行代码?

+1

这是否帮助你:https://stackoverflow.com/questions/44041698/java-9-no-class-definition-exception? – Steephen

+0

是的。这有助于。非常感谢主持人:) –

+0

@ Kavitha Karunakaran请给你的问题写一个答案,你是如何修改给定日食环境下的答案的。 – Steephen

回答

2

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

enter image description here

之后,代码运行平稳,没有抛出NoClassDefFoundError错误。