关于base64引用包的maven打包异常的填坑

欢迎大家来我的博客:http://www.qnloft.com 交流学习还可以观看视频教程

场景还原

如果你使用如下代码:

public String encodeBase64(byte[] binaryData) {
    return Base64.encode(binaryData);
}

public byte[] decodeBase64(String encoded) throws Base64DecodingException {
    return Base64.decode(encoded);
}

并且引入了com.sun.org.apache.xml.internal.security.utils包,或者是org.apache.xml.security.utils包,那么恭喜你,在执行maven打包命令的时候,会出现如下错误:

[ERROR] .....(这里是类路径) 程序包com.sun.org.apache.xml.internal.security.utils不存在

或者

[ERROR] .....(这里是类路径) 程序包org.apache.xml.security.utils不存在

这里我也犯懒,百度了一下,结果又被坑,来我们看一下我百度出了什么:

解决maven编译错误:程序包com.sun.xml.internal.ws.spi不存在

写的像模像样的,但是仔细推敲一下,MMB,怎么可能在多人开发的项目里面加

<compilerArguments>
    <bootclasspath>${JAVA_HOME}/jre/lib/rt.jarbootclasspath>
compilerArguments>

${JAVA_HOME}这个是自己jdk配置的路径,牛逼你在多人开发的项目pom文件里面写自己机器的jdk开发路劲吗???


来看看正解,直接上代码:

import java.util.Base64;

private static String encodeBase64(byte[] binaryData) {
    return Base64.getEncoder().encodeToString(binaryData);
}

private static byte[] decodeBase64(String encoded){
    return Base64.getDecoder().decode(encoded);
}

反正青柠是使用的java8,是由这个util的,如果小伙伴有使用java7的,留言一下是否有这个工具类。

你可能感兴趣的:(填坑之旅)