【问题标题】:package sun.awt does not exist包 sun.awt 不存在
【发布时间】:2019-10-16 16:34:06
【问题描述】:

使用 ant 编译时,调用 sun.awt.AppContext 可以工作,但是使用 IntelliJ 编译的相同代码使用 AdoptOpenJDK11 失败。

  • sun.awt.AppContextOracle JDK8 与 IntelliJ 一起使用
  • sun.awt.AppContextAdoptOpenJDK11 不适用于 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


    【解决方案1】:

    禁用使用'--release'选项...

    See this answer了解详情。

    【讨论】:

    • 谢谢,成功了。在 Mac 上,它位于 IntelliJ IDEA > Preferences > Build, Execution, Deployment > Java Compiler
    • 非常感谢,这也是我项目的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    • 2011-12-21
    • 2013-11-21
    • 2021-03-05
    • 2020-08-21
    • 2022-01-16
    • 2013-05-10
    相关资源
    最近更新 更多