小编Kav*_*ran的帖子

如何在JShell中运行作为片段添加的整个Java文件?

我尝试安装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)

java java-9 jshell

6
推荐指数
1
解决办法
1619
查看次数

尝试在Eclipse Oxygen中的Java中使用jdk.incubator.http.HttpClient时出现NoClassDefFoundError

这是我使用的代码片段:

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。但是,当我将与一起使用时,此功能可以完美--add-modules=jdk.incubator.httpclient。怎样才能使代码通过Eclipse执行?

java eclipse http2 jshell java-http-client

5
推荐指数
1
解决办法
808
查看次数

标签 统计

java ×2

jshell ×2

eclipse ×1

http2 ×1

java-9 ×1

java-http-client ×1