当前位置:   article > 正文

Macos快速切换JDK版本_mac 切换jdk 快捷

mac 切换jdk 快捷

一、概述

原理:动态修改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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
永久生效:
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

三、使用

j8
j11
j17
jv
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/667637
推荐阅读
相关标签
  

闽ICP备14008679号