包 sun.awt 不存在

package sun.awt does not exist

使用 ant 编译时,对 sun.awt.AppContext 的调用有效,但是使用 AdoptOpenJDK11 时使用 IntelliJ 编译的相同代码失败。

虽然Sun/Oracle有warned for a while about avoiding the sun.* packages, there are 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.* 包?

禁用使用“--release”选项...:

了解详情。