1.MAC终端无法使用mvn命令解决办法

现在的IDEA 自带maven库maven库的地址如下图查看

image.png

2.安装完idea 需要配置maven库的环境变量才能找到该命令

3.Mac系统的环境变量,加载顺序为:

  1. a. /etc/profile
  2. b. /etc/paths
  3. c. ~/.bash_profile
  4. d. ~/.bash_login
  5. e. ~/.profile
  6. f. ~/.bashrc
  7. 其中ab是系统级别的,系统启动就会加载。其余是用户级别的,c,d,e按照从前往后的顺序读取,如果c文件存在,则后面的几个文件就会被忽略不读了,以此类推。
  8. ~/.bashrc没有上述规则,它是bash shell打开的时候载入的。这里建议在c中添加环境变量

4.操作步骤

  1. vim ~/.bash_profile
  2. //将以下两行export加入bash_profile中保存退出
  3. export IDEA_MAVEN=/Applications/IntelliJ\ IDEA.app/Contents/plugins/maven/lib/maven3
  4. //注释:maven3 的地址可以显示包内容去查看,以查看的距离路径为准
  5. export PATH=$PATH:$IDEA_MAVEN/bin
  6. source ~/.bash_profile //在终端执行,使bash_profile生效

5.在终端输入mvn -v(出现没有权限的错误)

/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/mvn:
Permission denied

  • 没有执行权限,需要添加执行权限
  • cd 到maven3下的bin目录下

    1. cd /Applications/IntelliJ\ IDEA.app/Contents/plugins/maven/lib/maven3
  • 添加执行权限 (a:所有用户 +:增加权限 x:执行权限)

    1. chmod a+x mvn

    6.重新输入mvn -v 显示以下信息成功

    Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
    Maven home: /Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3
    Java version: 1.8.0_311, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_311.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”

    7.maven 如何添加没有开源的jar到本地中

    1.首先 cd到指定的目录
    2.指定groupId、artifatId、version、packaging、和文件名。如以下的命令:

    1. mvn install:install-file -DgroupId=com.aliyun -DartifactId=aliyun-sdk-vod-upload -Dversion=1.4.11 -Dpackaging=jar -Dfile=aliyun-java-vod-upload-1.4.11.jar

    3.在idea的maven中就可以添加依赖到项目中来

    1. <!--非开源jar-->
    2. <dependency>
    3. <groupId>com.aliyun</groupId>
    4. <artifactId>aliyun-sdk-vod-upload</artifactId>
    5. </dependency>

    8.idea中配置maven自动下载源代码和文档,这样可以方便调试代码

    image.png