---
title: "Access restriction: The type XXX is not accessible due to restriction on require"
author: "zybing"
date: "2013-01-06T09:14:53Z"
tags: []
categories: ["非技术"]
slug: "access-restriction-the-type-xxx-is-not-accessible-due-to-restriction-on-require"
draft: false
lastmod: "2013-01-06T09:14:53Z"
id: 1763020
url: "https://zybing.iteye.com/blog/1763020"
---

引用rt.jar中的一个类,结果发生了标题中的错误

"Access restriction: The type XXX is not accessible due to restriction on required library c:\\jdk\\jre\\lib\\rt.jar "

 

这个类应该没有什么问题的,估计是eclipse编译器的问题,网上查资料,发现eclipse中此类的问题不少,摘录一篇解决方法:

 

http://blog.csdn.net/hexin373/article/details/7175325

 

 ibrary C:\\Program Files\\Java\\jdk\\jre\\lib\\ext  
  \\jdsmsserver-3.4.jar

google了一下 下面是解决方法

Eclipse 默认把这些受访问限制的API设成了ERROR。只要把Windows-Preferences-Java-Complicer- Errors/Warnings里面的Deprecated and restricted API中的Forbidden references(access rules)选为Warning就可以编译通过。

不过这个不好

如果你的jre目录里面有你项目需要引用的jar包

而你又引用了外部jar包

也就是说引用了两次

如果你想让起作用的是手动引用的外部jar包 这个时候需要把 "Referenced Library" 调整到 "JRE System Library"上面

引用的顺序是从上到下

改变顺序前的效果:

![](http://hi.csdn.net/attachment/201201/4/0_1325664454k30r.gif)

build path

![](http://hi.csdn.net/attachment/201201/4/0_13256644961543.gif)

最后效果

![](http://hi.csdn.net/attachment/201201/4/0_1325664524Vduh.gif)

OK 一切正常...