Java mvn 命令在 mac OS X Yosemite 上不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34563701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:47:10  来源:igfitidea点击:

mvn command not working on mac OS X Yosemite

javamacosmaven

提问by John

I have performed all the necessary steps like the following after referring other Stack overflow threads and online resources for installing / configuring maven. Here is what I did :

在参考其他堆栈溢出线程和用于安装/配置 maven 的在线资源后,我已经执行了所有必要的步骤,如下所示。这是我所做的:

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9

export M2=$M2_HOME/bin

My Java Home variable is also, set, as shown below:

我的 Java Home 变量也已设置,如下所示:

echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home

export PATH=$M2:$PATH  

Inspite of doing all of the above, when I run mvn --version, I get Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home/bin/java.

尽管执行了上述所有操作,但当我运行时mvn --version,我得到Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home/bin/java.

PATH Output is as follows :

PATH 输出如下:

 echo $PATH
/usr/local/apache-maven/apache-maven-3.3.9/bin:/usr/local/apache-maven/apache-maven-3.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/MacGPG2/bin

采纳答案by 11thdimension

export PATH=$M2:$PATHshould be export PATH=$M2/bin:$PATHor export PATH=$M2_HOME/bin:$PATH

export PATH=$M2:$PATH应该是export PATH=$M2/bin:$PATHexport PATH=$M2_HOME/bin:$PATH

Also JAVA_HOME should be something like this

JAVA_HOME 也应该是这样的

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60

then

然后

export PATH=$JAVA_HOME/bin:$PATH

export PATH=$JAVA_HOME/bin:$PATH

That's all.

就这样。

All in one

一体

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60
export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH

回答by user3793706

I faced exactly the same problem and resolved it by getting the JAVA_HOME path by executing the following command: /usr/libexec/java_home -version

我遇到了完全相同的问题,并通过执行以下命令获取 JAVA_HOME 路径来解决它: /usr/libexec/java_home -version

output: java_home: option `-version' requires an argument /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

输出:java_home:选项`-version'需要一个参数 /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

Copy and paste this as value to JAVA_HOME and try again. It should work.

将此作为值复制并粘贴到 JAVA_HOME 并重试。它应该工作。