我有一个问题,编译单纯堵塞从HttpRequest的JavaDoc的GET例如:“包java.net.http不存在”错误上JDK9
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: error: package java.net.http does not exist import java.net.http.HttpRequest; ^ org.example.module1\src\org.example.module1\org\example\Http2.java:7: error: package java.net.http does not exist import java.net.http.HttpResponse; ^ org.example.module1\src\org.example.module1\org\example\Http2.java:9: error: package java.net.http does not exist import static java.net.http.HttpRequest.noBody; ^ org.example.module1\src\org.example.module1\org\example\Http2.java:9: error: static import only from classes and interfaces import static java.net.http.HttpRequest.noBody; ^ org.example.module1\src\org.example.module1\org\example\Http2.java:10: error: package java.net.http does not exist import static java.net.http.HttpResponse.asString; ^ org.example.module1\src\org.example.module1\org\example\Http2.java:10: error: static import only from classes and interfaces import static java.net.http.HttpResponse.asString; ^ org.example.module1\src\org.example.module1\org\example\Http2.java:14: error: cannot find symbol HttpResponse response = HttpRequest ^ symbol: class HttpResponse location: class Http2 org.example.module1\src\org.example.module1\org\example\Http2.java:14: error: cannot find symbol HttpResponse response = HttpRequest ^ symbol: variable HttpRequest location: class Http2 org.example.module1\src\org.example.module1\org\example\Http2.java:16: error: cannot find symbol .body(noBody()) ^ symbol: method noBody() location: class Http2 org.example.module1\src\org.example.module1\org\example\Http2.java:19: error: cannot find symbol String responseBody = response.body(asString()); ^ symbol: method asString() location: class Http2 10 errors
使用命令行和IntelliJ发生相同的错误。
这不是我的模块的问题,因为没有java.net.http的类编译和运行没有任何问题。
任何想法是怎么回事?
这已经过时了[用我相信的答案取代](https://stackoverflow.com/a/43111760/1746118) – nullpointer