赞
踩
原理:动态修改JAVA_HOME变量。
vim ~/.bash_profile
### JDK definition
JAVA_08="/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home"
JAVA_11="/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home"
JAVA_17="/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home"
### alias
alias j8='export JAVA_HOME=$JAVA_08 && echo "Switch to Java8"'
alias j11='export JAVA_HOME=$JAVA_11 && echo "Switch to Java11"'
alias j17='export JAVA_HOME=$JAVA_17 && echo "Switch to Java17"'
source ~/.bash_profile
vim ~/.bash_profile
### JDK definition
JAVA_08="/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home"
JAVA_11="/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home"
JAVA_17="/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home"
### alias
alias j8='sed -i "" "/export JAVA_HOME=\//d" ~/.bash_profile && echo "export JAVA_HOME=$JAVA_08" >> ~/.bash_profile && source ~/.bash_profile && echo "Switch to Java8"'
alias j11='sed -i "" "/export JAVA_HOME=\//d" ~/.bash_profile && echo "export JAVA_HOME=$JAVA_11" >> ~/.bash_profile && source ~/.bash_profile && echo "Switch to Java11"'
alias j17='sed -i "" "/export JAVA_HOME=\//d" ~/.bash_profile && echo "export JAVA_HOME=$JAVA_17" >> ~/.bash_profile && source ~/.bash_profile && echo "Switch to Java17"'
alias jv='java -version'
source ~/.bash_profile
j8
j11
j17
jv
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。