您现在的位置是: 首页 > 后端开发 类 BASE64Decoder 程序包 sun.misc 找不到符号

类 BASE64Decoder 程序包 sun.misc 找不到符号

2020-05-29 后端开发 7934人已围观 14547次浏览

简介类 BASE64Decoder 程序包 sun.misc 找不到符号

在修改一个老项目的时候,打包出现提示

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project : Compilation failure
[ERROR] FileUtil.java:[7,16] 找不到符号
[ERROR]   符号:   类 BASE64Decoder
[ERROR]   位置: 程序包 sun.misc
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

根据提示查看文件发现,在 Base64 转换的地方使用的是 Sun 的专用 API

import sun.misc.BASE64Decoder;

BASE64Decoder decoder = new BASE64Decoder();
byte[] b = decoder.decodeBuffer(base64);

其实这个 API 在很早之前,打包的时候就会提示

sun.misc.BASE64Encoder 是 Sun 的专用 API,可能会在未来版本中删除

解决方案就是引用 Apache Commons Codec

<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.14</version>
</dependency>

然后修改代码为

import org.apache.commons.codec.binary.Base64;

byte[] b = Base64.decodeBase64(base64);

重新打包则问题解决

很赞哦! (0)

站长推荐

站点信息

  • 网站地图