【问题标题】:"package java.net.http does not exist" error on JDK9JDK9上的“包java.net.http不存在”错误
【发布时间】:2016-04-28 09:36:45
【问题描述】:
我在从 HttpRequest JavaDoc 编译简单的阻塞 GET 示例时遇到问题:
package org.example;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import static java.net.http.HttpRequest.noBody;
import static java.net.http.HttpResponse.asString;
public class Http2 {
public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
HttpResponse response = HttpRequest
.create(new URI("http://www.infoq.com"))
.body(noBody())
.GET().response();
int responseCode = response.statusCode();
String responseBody = response.body(asString());
System.out.println(responseBody);
}
}
使用 JDK 9 编译时出现package java.net.http does not exist 错误:
{ jdk9 } » /cygdrive/c/Program\ Files/Java/jdk-9/bin/javac -d out/production -modulesourcepath org.example.module1/src/ -m org.example.module1
org.example.module1\src\org.example.module1\org\example\Http2.java:6: 错误:包 java.net.http 不存在
导入 java.net.http.HttpRequest;
^
org.example.module1\src\org.example.module1\org\example\Http2.java:7: 错误:包 java.net.http 不存在
导入 java.net.http.HttpResponse;
^
org.example.module1\src\org.example.module1\org\example\Http2.java:9: 错误:包 java.net.http 不存在
导入静态 java.net.http.HttpRequest.noBody;
^
org.example.module1\src\org.example.module1\org\example\Http2.java:9:错误:仅从类和接口静态导入
导入静态 java.net.http.HttpRequest.noBody;
^
org.example.module1\src\org.example.module1\org\example\Http2.java:10:错误:包 java.net.http 不存在
导入静态 java.net.http.HttpResponse.asString;
^
org.example.module1\src\org.example.module1\org\example\Http2.java:10:错误:仅从类和接口静态导入
导入静态 java.net.http.HttpResponse.asString;
^
org.example.module1\src\org.example.module1\org\example\Http2.java:14:错误:找不到符号
HttpResponse 响应 = HttpRequest
^
符号:类 HttpResponse
位置:类 Http2
org.example.module1\src\org.example.module1\org\example\Http2.java:14:错误:找不到符号
HttpResponse 响应 = HttpRequest
^
符号:变量 HttpRequest
位置:类 Http2
org.example.module1\src\org.example.module1\org\example\Http2.java:16:错误:找不到符号
.body(noBody())
^
符号:方法 noBody()
位置:类 Http2
org.example.module1\src\org.example.module1\org\example\Http2.java:19:错误:找不到符号
字符串 responseBody = response.body(asString());
^
符号:方法 asString()
位置:类 Http2
10 个错误
使用命令行和 IntelliJ 也会出现同样的错误。
我的模块没有问题,因为没有 java.net.http 的类编译和运行没有任何问题。
知道发生了什么吗?
【问题讨论】:
标签:
java
java-9