☁ server [master] ⚡ mvn dependency:tree
zsh: command not found: mvn
mvn 命令找不到,应该是maven指向问题
方法一
然后执行:
☁ server [master] ⚡ source ~/.bash_profile
☁ server [master] ⚡ mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.server:data >---------------------------
[INFO] Building data 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ data ---
[INFO] Deleting /Users/work/projects/server/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.230 s
[INFO] Finished at: 2022-04-27T15:06:53+08:00
[INFO] ------------------------------------------------------------------------
问题:
一旦重启命令窗口,问题依旧出现。
方法二
首先检测bash_profile有没有环境配置,如果有则忽略
☁ server [master] ⚡ cat ~/.bash_profile
..
export M2_HOME="/Users/admin/apache-maven-3.6.3"
export PATH="$M2_HOME/bin:$PATH"
..
然后检测zsh_profile中的环境变量
☁ server [master] ⚡ vim ~/.zshrc
# 在文件最下方追加
source ~/.bash_profile
☁ server [master] ⚡ source ~/.zshrc
☁ server [master] ⚡ mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/admin/apache-maven-3.6.3
Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: /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"
然后,无论怎么新开命令窗口,命令都不会失效了