代码如下:

package mscontroller;

import javax.swing.*;
import com.apple.eawt.Application;

public class Main {
    public static void main(String[] args)
    {
        Application app = new Application();
        app.setEnabledAboutMenu(true);

        AMEListener listener = new AMEListener();
        app.addApplicationListener(listener);
        JFrame mainFrame = new JFrame("Application Menu Example");
        mainFrame.setSize(500, 500);
        mainFrame.setVisible(true);
    }
}

错误如下:

Exception in thread "main" java.lang.Error: Unresolved compilation
problems:   Access restriction: The type 'Application' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
    Access restriction: The constructor 'Application()' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
    Access restriction: The type 'Application' is not API (restriction on
required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
    Access restriction: The method
'Application.setEnabledAboutMenu(boolean)' is not API (restriction on
required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
    AMEListener cannot be resolved to a type    AMEListener cannot be
resolved to a type

    at mscontroller.Main.main(Main.java:9)

Eclipse说:

访问限制:'Application'类型不是API(对必需库'/ library /Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar'的限制)


当前回答

我们使用IBM Rational Application Developer (RAD),也遇到了同样的问题。

ErrorMessage:

访问限制:'JAXWSProperties'类型不是API(对必需库'C:\IBM\RAD95\jdk\jre\lib\rt.jar'的限制)

解决方案:

进入java构建路径,在Library标签下,删除JRE System Library。然后再次添加库—> JRE系统库

其他回答

我遇到了一个不同的问题。在项目-属性-库- JRE库,我有错误的JRE库版本。删除并设置实际的一个,瞧——所有的访问限制…警告消失了。

即使它的老问题,对我来说,在Eclipse中,我只是右键单击Src文件夹和属性(Alt+Enter),检查忽略可选编译问题消除了错误。

在Eclipse顶部菜单栏中:

Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> 
Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning

它工作:项目属性-> ProjectFacets ->运行时-> jdk1.8.0_45 ->应用

进入以下设置:

窗口->首选项-> java -编译器-错误/警告-弃用和限制api -禁止引用(访问规则)

设置为“警告”或“忽略”。