jdk8升级jdk11/jdk17记录
1,本地安装jdk11或jdk17,配置环境变量,可配置多版本随时切换,方便回退,默认使用jdk1.8
export JAVA_8_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home"
export JAVA_11_HOME="/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home"
export JAVA_17_HOME="/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home"
export PATH=$JAVA_HOME/bin:$PATH:.
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
alias jdk11='export JAVA_HOME=$JAVA_11_HOME'
alias jdk17='export JAVA_HOME=$JAVA_17_HOME'
# 默认用JDK1.8
export JAVA_HOME=$JAVA_8_HOME
2,idea添加jdk
3:修改工程当前jdk版本
4:重启发现,发现缺失import sun.misc.BASE64Encoder;
因为在JDK1.8中的/lib/tool.jar和/lib/rt.jar已经从Java SE 9中删除,所以在项目中,设计到64位编码的。可引用 import org.apache.commons.codec.binary.Base64;进行替换
将:import sun.misc.BASE64Encoder;
替换为:import org.apache.commons.codec.binary.Base64;
代码中将:new BASE64Encoder().encode(bytes)
public static String base64Encode(byte[] bytes){
return new BASE64Encoder().encode(bytes);
}
替换为:Base64.encodeBase64String(bytes);
public static String base64Encode(byte[] bytes){
return Base64.encodeBase64String(bytes);
}
将:new BASE64Decoder().decodeBuffer(base64Code)
public static byte[] base64Decode(String base64Code) throws Exception{
return StringUtils.isEmpty(base64Code) ? null : new BASE64Decoder().decodeBuffer(base64Code);
}
替换为:Base64.decodeBase64(base64Code)
public static byte[] base64Decode(String base64Code) throws Exception{
return StringUtils.isEmpty(base64Code) ? null : Base64.decodeBase64(base64Code);
}
原文链接
https://blog.csdn.net/weixin_38006002/article/details/132876871