【发布时间】:2019-10-16 16:34:06
【问题描述】:
使用 ant 编译时,调用 sun.awt.AppContext 可以工作,但是使用 IntelliJ 编译的相同代码使用 AdoptOpenJDK11 失败。
-
sun.awt.AppContext与 Oracle JDK8 与 IntelliJ 一起使用 -
sun.awt.AppContext与 AdoptOpenJDK11 不适用于 IntelliJ
虽然 Sun/Oracle 有 warned for a while 关于避免使用 sun.* 包,但有 certain features (bugs?) in Java that still require them 和陌生人,命令行似乎很高兴。
示例代码:
package test;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import sun.awt.AppContext;
public class Main {
public static void main(String[] args) {
//Update printer list in CUPS immediately
AppContext.getAppContext().put(PrintServiceLookup.class.getDeclaredClasses()[0], null);
PrintService[] printers = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService p : printers) {
System.out.println(p.getName());
}
}
}
如何配置 IntelliJ 使其行为类似于 ant 并允许访问 sun.awt.* 包?
【问题讨论】:
标签: java intellij-idea java-11 openjdk-11 adoptopenjdk