当前位置:   article > 正文

Mac上Maven 执行mvn -v,提示JAVA_HOME没有正确配置_mac the java_home environment variable is not defi

mac the java_home environment variable is not defined correctly, this enviro

问题场景:Mac上在装好JDK和JRE后安装Maven,提示JAVA_HOME没有正确配置,错误信息如下

  1. ➜  ~ mvn -v
  2. The JAVA_HOME environment variable is not defined correctly,
  3. this environment variable is needed to run this program.

在配置文件中的配置为:

  1. export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-1.8.0_211.jdk/Contents/Home
  2. export PATH=$JAVA_HOME/bin:/usr/local/bin:$PATH
  3. export CLASS_PATH=$JAVA_HOME/lib
  4. #Maven
  5. export MAVEN_HOME=/Library/Java/JavaVirtualMachines/apache-maven-3.8.6
  6. export PATH=$MAVEN_HOME/bin:$PATH

环境变量的配置本身没有问题,但因为某些特殊字符的原因,造成了系统无法直接访问jdk的安装目录,报错信息如下

  1. ➜ ~ cd /Library/Java/JavaVirtualMachines/jdk-1.8.0_211.jdk
  2. cd: no such file or directory: /Library/Java/JavaVirtualMachines/jdk-1.8.0_211.jdk

将目录名改为不含特殊字符的文件名,使系统能够直接访问

  1. # 将复杂文件名改为简单文件名
  2. sudo mv jdk1.8.0_211.jdk jdk8

改动文件名后,系统可以直接访问,此时再修改jdk的配置路径

  1. # 环境变量设置为:
  2. export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk8/Contents/Home
  3. export PATH=$JAVA_HOME/bin:/usr/local/bin:$PATH
  4. export CLASS_PATH=$JAVA_HOME/lib
  5. #Maven
  6. export MAVEN_HOME=/Library/Java/JavaVirtualMachines/apache-maven-3.8.6
  7. export PATH=$MAVEN_HOME/bin:$PATH

改动文件后记得保存改动,并在终端中执行

source ~/.bash_profile

最后,执行mnv -v查看结果

  1. ➜ ~ mvn -v
  2. Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
  3. Maven home: /Library/Java/JavaVirtualMachines/apache-maven-3.8.6
  4. Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk8/Contents/Home/jre
  5. Default locale: zh_CN, platform encoding: UTF-8
  6. OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

问题解决!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/187506
推荐阅读
相关标签
  

闽ICP备14008679号