eclipse Java导入jar包提示Access restriction解决方法

来源:互联网 发布:mac os清理软件 编辑:程序博客网 时间:2024/06/05 19:20

在使用RXTXcomm.jar 编写串口通信程序提示错误:
Access restriction: The type ‘CommPortIdentifier’ is not API
(restriction on required library ‘C:\Program Files\Java\jre1.8.0_131\lib\ext\RXTXcomm.jar’)

问题原因:Eclipse 默认把这些受访问限制的API设成了ERROR

解决方法:
1. Windows-> Preferences -> Java -> Compiler -> Errors/Warnings ->Deprecatedand trstricted API -> Forbidden reference (access rules): -> Error改为Warning即可。
2. 只需要在projectbuild path中先移除JRESystem Library,再添加库JRESystem Library,重新编译后就一切正常了。
3. 工程上右键->工程属性->javabuilder path->Libraries标签,点击JRE SystemLibrary里面的Accessrules,addsun/** 为accessible,如果该项存在,就edit。
4. Windows-> Preferences -> Java -> Installed JREs -> 选择用的JDK-> Edit -> Add External JARs

原创粉丝点击