代码如下:

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'的限制)


当前回答

在eclipse oxygen中添加javafx可访问权限 进入项目>属性> java构建路径> libraries>,然后展开库,双击>访问规则,在那里设置权限 解决方案:无障碍 规则模式:javafx/**

其他回答

我只是简单地在eclipse市场中添加e(fx)clipse。简单明了

如果你在使用Spring工具套件时有同样的问题:

Spring工具套件的底层IDE实际上是Eclipse。我刚刚在尝试使用一些com.sun.net类时得到了这个错误。要删除这些错误并防止它们在STS的Eclipse Luna SR1(4.4.2)平台中弹出:

导航到项目>属性 展开Java Compiler标题 点击错误/警告 扩展已弃用和受限的API 在“禁止引用(访问规则)”旁边选择“忽略” 在“不鼓励引用(访问规则)”旁边选择“忽略”

你可以出发了。

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

我也有同样的问题。以下是我的解决方法: 进入包资源管理器。右键单击JRE系统库,然后进入属性。在类路径容器>中为项目构建路径选择JRE,选择第三个选项(工作区默认JRE)。

来源:https://thenewboston.com/forum/topic.php?id=3917

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

ErrorMessage:

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

解决方案:

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