maven installation under mac 10.10.2

Since you want to install maven, you must first download it.

The way to install software on mac is actually very simple

1:sudo brew install maven;

Is it very simple, one sentence to get it.

The next thing is a headache. When using mvn -v, an error message appears.

Error: JAVA_HOME is not defined correctly.
  We cannot execute /usr/libexec/java_home/bin/java

 Well, the reason for this error is that our JAVA_HOME has not been set.

A little dizzy. . .

Because the brew install command was also used when installing jdk at that time. I don't remember setting the environment variables at that time.

It is estimated that brew install has already installed these.

OK, in this case, go directly to the /etc/profile file to configure java_home and find it on the Internet,

/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/

 After saving, use the source command to make it take effect.

Now we use

echo $JAVA_HOME

 It shows exactly the path we configured above. Very satisfied, I think it should be ok

Then we tried again with mvn -v.

The result made us laugh again. Still the same error. We started to feel that something was wrong and that it shouldn't be.

Then we checked again.

Check the information and get Apple's recommendation that you set JAVA_HOME to  /usr/libexec/java_home

 

export JAVA_HOME=$(/usr/libexec/java_home)

We will delete the JAVA_HOME under the previous etc/profile.

Try again

echo $JAVA_HOME

 The result is the location of the jdk.

try mvn -v again

zhichengzhangdeMacBook-Pro:~ Thomas$ mvn -v
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

 I think this should be considered a good match.

However, this configuration is not preserved when the console is closed. So we have to write the content into /etc/profile. Then use the source command to make it take effect.

 

All right. The steps are simple. .

in conclusion:

1:sudo brew install maven
2: Open /etc/profile and add the following sentence at the end.
export JAVA_HOME=$(usr/libexec/java_home)
3:source /etc/profile
4:mvn -v

 ps: my system is mac os 10.10.2 maven 3.2.5

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326442466&siteId=291194637