一、系统环境
组件 | 版本 |
---|---|
MacOS | 11.4 |
Idea | 2021.1 Ultimate Edition |
二、Idea 内置Maven
1、setting.xml
新建访达窗口,选择home目录按下“command+shift+.”三个键,显示隐藏目录和文件
如果要隐藏则再按一下即可。
进入“.m2”文件夹,编辑setting.xml即可
<!-- 在mirror下添加额外镜像地址 -->
<!-- 阿里云中央仓库 159行 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
2、idea的maven加入环境变量
参考:idea for mac 控制台 mvn command not found
简述
Mac系统的环境变量,加载顺序为:
a. /etc/profile
b. /etc/paths
c. ~/.bash_profile
d. ~/.bash_login
e. ~/.profile
f. ~/.bashrc
其中a和b是系统级别的,系统启动就会加载。其余是用户级别的,c,d,e按照从前往后的顺序读取,如果c文件存在,则后面的几个文件就会被忽略不读了,以此类推。
~/.bashrc没有上述规则,它是bash shell打开的时候载入的。这里建议在c中添加环境变量
操作步骤如下
vim ~/.bash_profile
export IDEA_MAVEN=/Applications/IntelliJ\ IDEA.app/Contents/plugins/maven/lib/maven3
export PATH=$PATH:$IDEA_MAVEN/bin 备注:因为我直接用的idea自带的maven插件,所以直接导入
source ~/.bash_profile 备注:生效一下
在控制台输入mvn -v报错:
Permission denied
解决方法
给mvn增加执行权限
chmod a+x /Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/mvn
如果无法识别IntelliJ IDEA.app这个文件夹,那就
cd 到最后一层bin目录下, chmod a+x mvn (a:所有用户 +:增加权限 x:执行权限)
继续输入仍然报错:
zsh: command not found: mvn
参考:mac安装maven后,遇到zsh: command not found: mvn的问题
# 创建或打开文件
vim ~/.zshrc
# 在文件末尾增加
source ~/.bash_profile
# 如果maven环境变量配置在/etc/profile,则添加
source /etc/profile