赞
踩
问题场景:Mac上在装好JDK和JRE后安装Maven,提示JAVA_HOME没有正确配置,错误信息如下
- ➜ ~ mvn -v
- The JAVA_HOME environment variable is not defined correctly,
- this environment variable is needed to run this program.
在配置文件中的配置为:
- export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-1.8.0_211.jdk/Contents/Home
- export PATH=$JAVA_HOME/bin:/usr/local/bin:$PATH
- export CLASS_PATH=$JAVA_HOME/lib
-
- #Maven
- export MAVEN_HOME=/Library/Java/JavaVirtualMachines/apache-maven-3.8.6
- export PATH=$MAVEN_HOME/bin:$PATH
环境变量的配置本身没有问题,但因为某些特殊字符的原因,造成了系统无法直接访问jdk的安装目录,报错信息如下
- ➜ ~ cd /Library/Java/JavaVirtualMachines/jdk-1.8.0_211.jdk
- cd: no such file or directory: /Library/Java/JavaVirtualMachines/jdk-1.8.0_211.jdk
将目录名改为不含特殊字符的文件名,使系统能够直接访问
- # 将复杂文件名改为简单文件名
- sudo mv jdk1.8.0_211.jdk jdk8
改动文件名后,系统可以直接访问,此时再修改jdk的配置路径
- # 环境变量设置为:
- export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk8/Contents/Home
- export PATH=$JAVA_HOME/bin:/usr/local/bin:$PATH
- export CLASS_PATH=$JAVA_HOME/lib
-
- #Maven
- export MAVEN_HOME=/Library/Java/JavaVirtualMachines/apache-maven-3.8.6
- export PATH=$MAVEN_HOME/bin:$PATH
改动文件后记得保存改动,并在终端中执行
source ~/.bash_profile
最后,执行mnv -v查看结果
- ➜ ~ mvn -v
- Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
- Maven home: /Library/Java/JavaVirtualMachines/apache-maven-3.8.6
- Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk8/Contents/Home/jre
- Default locale: zh_CN, platform encoding: UTF-8
- OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
问题解决!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。