一 java 多版本管理
使用 jenv, 地址:https://github.com/jenv/jenv
mac 操作
brew install jenv# Shell: zsh
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc
source ~/.zshrc
需要把JAVA_HOME 注释,搜索
grep -E 'JAVA_HOME|PATH' ~/.bash_profile ~/.profile ~/.bashrc ~/.zshrc
jenv 检测
jenv doctor
检测之前是否安装java
/usr/libexec/java_home -V如果有会出现
Matching Java Virtual Machines (4):20.0.1 (arm64) "Oracle Corporation" - "Java SE 20.0.1" /Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home17.0.8 (arm64) "Amazon.com Inc." - "Amazon Corretto 17" /Users/admin/Library/Java/JavaVirtualMachines/corretto-17.0.8.1/Contents/Home11.0.20 (arm64) "Amazon.com Inc." - "Amazon Corretto 11" /Users/admin/Library/Java/JavaVirtualMachines/corretto-11.0.20.1/Contents/Home1.8.0_382 (arm64) "Amazon" - "Amazon Corretto 8" /Users/admin/Library/Java/JavaVirtualMachines/corretto-1.8.0_382/Contents/Home
使用 jenv add 添加java 版本
例如:
jenv add /Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Homejenv add /Users/admin/Library/Java/JavaVirtualMachines/corretto-17.0.8.1/Contents/Ho
检查
jenv doctorjenv versionsjenv which java
设置全局版本:
jenv global 1.8 # system 这个就是使用全局的
当前目录使用该版本jenv local 命令在当前目录中创建了一个 .java-version 文件
jenv local 1.8
Maven 安装
地址: https://maven.apache.org/install.html
解压,然后复制到
sudo mv apache-maven-3.9.8 /usr/local/
然后vim ~/.zshrc
export M2_HOME=/usr/local/apache-maven-3.9.8
export PATH=$PATH:$M2_HOME/bin最后 source ~/.zshrc
阿里镜像
找到 /usr/local/apache-maven-3.9.8/conf/settings.xml
修改部分
<mirrors><mirror><id>aliyunmaven</id><mirrorOf>*</mirrorOf><name>阿里云公共仓库</name><url>https://maven.aliyun.com/repository/public</url></mirror>
</mirrors>
基础命令 mvn clean install ,mvn install ,mvn package