我尝试安装JDK 9 Early access version 172来玩JShell.当我尝试打开一个简单的java文件并在将其添加为片段后执行它时,它只显示了修改后的类Test并增加了片段编号.你能帮我理解我哪里出错了吗?
| Welcome to JShell -- Version 9-ea
| For an introduction type: /help intro
jshell> /open G:\kavitha\Test.java
jshell> /list
1 : public class Test{
public static void main(String[] args){
int i = 1;
int j = 2;
System.out.println("Sum of 1 and 2 is : " + (i+j));
}
}
jshell> /1
public class Test{
public static void main(String[] args){
int i = 1;
int j = 2;
System.out.println("Sum of 1 and 2 is : …Run Code Online (Sandbox Code Playgroud) 这是我使用的代码片段:
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);
Run Code Online (Sandbox Code Playgroud)
NoClassDefFoundError当我运行上面的代码时,Eclipse抛出HttpClient。但是,当我将jshell与一起使用时,此功能可以完美运行--add-modules=jdk.incubator.httpclient。怎样才能使代码通过Eclipse执行?