Eclipse Access Restriction

来源:互联网 发布:工业建模软件 编辑:程序博客网 时间:2024/06/11 09:06

Question:

Access restriction: the type * is not accessible due to restriction on required library *.jar

Access restriction:The method * is not accessible due to restriction on required library *.jar

Description:

Eclipse环境下,项目中导入某些JAR,使用这些JAR中的某些API。结果出现Access restriction错误,如下图:

Accuse:

Access restriction的原因是因为这些JAR默认包含了一系列的代码访问规则(Access Rules),如果代码中引用了这些访问规则所禁止引用类,那么就会提示这个错误信息。

Action:

一、既然存在访问规则,那么修改访问规则即可。打开项目的Build Path Configuration页面,打开报错的JAR包,选中Access rules条目,选择右侧的编辑按钮,添加一个访问规则即可。

二、网上的另外一种解决方案:Window - preference - Java - Compiler - Errors/Warnings界面的Deprecated and restricted API下。把Forbidden reference (access rules): 的规则由默认的Error改为Warning。

这种方案是修改整个Eclipse开发环境,将所有禁止访问的引用由原来的Error(默认)修改为Warning。这种规避方式比较粗暴,个人支持第一种方案。


原文地址:http://hi.baidu.com/oritenson/blog/item/9b6c072a90a1dce199250a8e.html

原创粉丝点击