有时候为了实现某些功能而使用一些比较奇怪的jar包例如以下这类包:
com.sun.image.codec.jpeg.ImageFormatException;
com.sun.image.codec.jpeg.JPEGCodec;
com.sun.image.codec.jpeg.JPEGImageDecoder;
com.sun.image.codec.jpeg.JPEGImageEncoder;
常常因为Eclipse 默认把这些受访问限制的API设成了ERROR,会报出Access restriction的错误:
有一个比较简单可以马上解决这类错误的方法,虽然不太推荐,但是在紧急需要使用但是又没其他办法的情况下还是蛮好用的:
打开eclipse,Windows-Preferences-Java-Complicer- Errors/Warnings
把Deprecated and restricted API中的Forbidden references(access rules)选为Warning就可以编译通过。