[英]package sun.net.www.protocol.https is declared in module java.base, which does not export it
我正在嘗試使用 gradle6.6 構建一個 java 項目並在 eclipse 03-2020 中打開 jre 11.0.2。 我在構建使用 jrt-fs.jar 中的類的項目時面臨編譯問題; eg'sun.net.www.protocol.http.Handler',在open jre 11中。
public class Manager extends sun.net.www.protocol.https.Handler{
(package sun.net.www.protocol.https is declared in module java.base, which
does not export it)
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
以下是我的 build.gradle:
apply plugin: 'java'
apply plugin: 'application'
allprojects {
apply plugin: 'java'
sourceCompatibility = '11.0.2'
targetCompatibility = JavaVersion.VERSION_11
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
compile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
compile group: 'junit', name: 'junit', version: '4.10'
compile group: 'jmock', name: 'jmock', version: '1.0.1'
compile group: 'com.google.code.findbugs',name: 'findbugs', version: '1.3.9'
compile group: 'cglib', name: 'cglib', version: '2.1'
testCompile group: 'junit', name: 'junit', version: '4.10'
}
另外,如何避免通過 gradle 構建測試類?
正如@dave_thompson_085 建議的那樣,問題是由於 sun.net.* 包上的模塊化限制(JDK-1.9 及更高版本),因為它們是 JDK 內部的。 上面的包可以在 JDK -1.8 中訪問。 我們需要修復我們的代碼
如果您使用的是 gradle,請在 build.gradle 中添加此 compilerArgs
options.encoding = "UTF-8"
options.incremental = true
options.compilerArgs.addAll([
"--add-exports",
"java.base/sun.net.www.protocol.http=ALL-UNNAMED"
])
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.