Mac修改文件 ~/.bash_profile
# 定义不同版本的maven_home
export M2_HOME_DEFAULT=/Users/domino/files/maven_default
export M2_HOME_DMN=/Users/domino/files/maven_dmn
# 给M2_HOME默认值 这个必须要有,否则会出现找不到mvn命令的情况
export M2_HOME=$M2_HOME_DEFAULT
# 定义不同版本jdk的java_home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
# 给JAVA_HOME默认值 这个必须要有
export JAVA_HOME=$JAVA_8_HOME
# alias命令动态切换JDK版本
alias jdk8="export JAVA_HOME=$JAVA_8_HOME;export M2_HOME=$M2_HOME_DEFAULT"
alias jdk8_dmn="export JAVA_HOME=$JAVA_8_HOME;export M2_HOME=$M2_HOME_DMN"
alias jdk17_dmn="export JAVA_HOME=$JAVA_17_HOME;export M2_HOME=$M2_HOME_DMN"
export M2_BIN_HOME=$M2_HOME/bin
export PATH=$PATH:$M2_BIN_HOME
export PATH=/Users/domino/.ssh/:$PATH
省略。。。。。。。
修改完后,执行source ~/.bash_profile
命令使改动生效
效果
# 切换jdk8
(base) domino@localhost IdeaProjects % jdk8
(base) domino@localhost IdeaProjects % mvn -v
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)
Maven home: /Users/domino/files/maven_koolearn
Java version: 1.8.0_241, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
# 切换jdk8+特定maven
(base) domino@localhost IdeaProjects % jdk8_dmn
(base) domino@localhost IdeaProjects % mvn -v
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)
Maven home: /Users/domino/files/maven_dmn
Java version: 1.8.0_241, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
# 切换jdk17+指定maven
(base) domino@localhost IdeaProjects % jdk17_dmn
(base) domino@localhost IdeaProjects % mvn -v
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)
Maven home: /Users/domino/files/maven_dmn
Java version: 17.0.11, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "11.2.1", arch: "x86_64", family: "mac"