package sun.awt does not exist

↘锁芯ラ 提交于 2019-12-07 07:14:44

问题


When compiling with ant, calls to sun.awt.AppContext work, however the same code compiled with IntelliJ fails using AdoptOpenJDK11.

  • sun.awt.AppContext with Oracle JDK8 works with IntelliJ
  • sun.awt.AppContext with AdoptOpenJDK11 does NOT work with IntelliJ

Although Sun/Oracle has warned for a while about avoiding the sun.* packages, there are certain features (bugs?) in Java that still require them and stranger, the command line seems happy.

Sample code:

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());
        }
    }
}

How does one configure IntelliJ to behave like ant and allow access to sun.awt.* packages?


回答1:


Disable the Use '--release' option...:

See this answer for details.



来源:https://stackoverflow.com/questions/56388086/package-sun-awt-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!