简体   繁体   English

无法在Mac OSX上设置Maven

[英]Can't set up Maven on Mac OSX

I am new to Mac OSX and I'm running Yosemite. 我是Mac OSX的新手,并且正在运行Yosemite。 I am trying to set up Maven using this official guide in order to set up a Google Cloud Messaging Backend. 我正在尝试使用此官方指南设置Maven,以设置Google Cloud Messaging Backend。 Here's what I did: 这是我所做的:

1) Downloaded Maven zip (version: apache-maven-3.3.9) and Unzipped it 1)下载Maven zip(版本:apache-maven-3.3.9)并解压缩

2) As the guide says, I need to add the bin directory to my PATH variable. 2)如指南所述,我需要将bin目录添加到我的PATH变量中。 So I did the following in my terminal 所以我在终端中做了以下操作

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

The terminal didn't return any response. 终端未返回任何响应。 However when I checked to see if Maven got installed using: 但是,当我检查是否使用以下方法安装了Maven时:

mvn -version mvn版本

I get a message saying: 我收到一条消息说:

-bash: mvn: command not found -bash:mvn:找不到命令

What am I doing wrong? 我究竟做错了什么? Did I follow the steps properly to set up Maven? 我是否按照正确的步骤设置了Maven?

EDIT: 编辑:

MVN Bin Directory path is: MVN Bin目录路径为:

/Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9 /Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9

The $PATH is what point where your programs are, because of that you change it in order to find mvn . $PATH是程序所在的位置,因为您要更改它才能找到mvn Actually you are pointing $PATH to $M2_HOME/bin . 实际上,您将$PATH指向$M2_HOME/bin

You need to update $M2_HOME to one directory level before mvn bin and before update $PATH . 您需要在mvn bin之前和$PATH之前将$M2_HOME更新到一个目录级别。

If this is your mvn home: 如果这是您的MVN家:

/Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9

you should use this env vars: 您应该使用以下环境变量:

export M2_HOME="/Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_60"
export PATH="$JAVA_HOME/bin:$M2_HOME/bin:$PATH"

You can also edit your ~/.profile in order to include these lines, so you don't need to type these exports whenever you open your terminal. 您也可以编辑~/.profile以便包含这些行,因此在打开终端时无需键入这些exports

I tried all the manual steps here and still couldn't get it to work. 我在这里尝试了所有手动步骤,但仍然无法正常工作。 Then I realized I can easily install it using Homebrew , much more convenient: 然后我意识到我可以使用Homebrew轻松安装它,更加方便:

brew install maven

that's all you need to install maven for mac! 这就是为Mac安装Maven所需的全部!

export M2_HOME=/Users/Earthling/Documents/Projects/MobiProject/apache-maven-3.3.9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM