java 访问限制:类型 'BASE64Decoder' 不是 API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44268690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access restriction: The type 'BASE64Decoder' is not API
提问by user8049659
I'm trying to convert old project into maven project. But when project is maven then it shows warnings on class with import:
我正在尝试将旧项目转换为 maven 项目。但是当项目是 maven 时,它会在带有导入的类上显示警告:
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
Access restriction: The type 'BASE64Decoder' is not API (restriction on required library 'C:\Program Files\Java\jre7\lib\rt.jar')
访问限制:类型“BASE64Decoder”不是API(对所需库“C:\Program Files\Java\jre7\lib\rt.jar”的限制)
So what is the problem with it?
那么它有什么问题呢?
采纳答案by CuE
You can either replace sun.misc.BASE64Encoder& sun.misc.BASE64Decoderwith other BASE64 class e.g. Apache commonsor use:
您可以使用其他 BASE64 类(例如Apache commons)替换sun.misc.BASE64Encoder和sun.misc.BASE64Decoder或使用:
java.util.Base64;
Base64.getDecoder().decode(...);
Base64.getEncoder().encodeToString(...);
回答by VGR
All sun.* and com.sun.* packages are private to a Java implementation. Any future release of Java may alter them, possibly in ways which may break application code that relies on them.
所有 sun.* 和 com.sun.* 包都是 Java 实现私有的。Java 的任何未来版本都可能会改变它们,可能会破坏依赖它们的应用程序代码。
In contrast, all classes in java.*, javax.* and javafx.* packages are set in stone. Their names and their public members will not change and will not be removed (except, in theory, the deprecated ones).
相比之下,java.*、javax.* 和 javafx.* 包中的所有类都是一成不变的。他们的名字和他们的公共成员不会改变,也不会被删除(理论上,已弃用的除外)。
That is why you're getting a message that those classes are not part of the public API. They are not meant for public consumption.
这就是为什么您会收到一条消息,指出这些类不是公共 API 的一部分。它们不适合公共消费。
As of Java 8, you should be using java.util.Base64instead. However, it looks like you're using Java 7, so you'll want to use DatatypeConverter.parseBase64Binaryand DatatypeConverter.printBase64Binaryinstead.
从 Java 8 开始,您应该改用java.util.Base64。但是,看起来您使用的是 Java 7,因此您需要改用DatatypeConverter.parseBase64Binary和DatatypeConverter.printBase64Binary。
It should also be mentioned that Java 9, which is expected to be released in July 2017, will not allow programs to access sun.* classes. See https://mreinhold.org/blog/jigsaw-module-system.
还应该提到的是,预计将于 2017 年 7 月发布的 Java 9 将不允许程序访问 sun.* 类。请参阅https://mreinhold.org/blog/jigsaw-module-system。