[Maven] $JAVA_HOME Is Not Defined Correctly On Mac OSX ?

Hello,

You might encounter such an error while installing Maven on Mac. You cannot move on with the installation until you fix this issue.

There is a simple fix for this kind of problem.

Apple recommends to set JAVA_HOME to “/usr/libexec/java_home

For example:

$vim .bash_profile

$export JAVA_HOME = /usr/libexec/java_home

$source .bash_profile

But, when execute the Maven command, it prompts following error messages:

$mvn –version

Error: JAVA_HOME is not defined correctly.

We cannot execute /usr/libexec/java_home/bin/java

Solution :

To fix it, update the JAVA_HOME like following:

$vim .bash_profile

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

$source .bash_profile

Run Maven again:

$mvn –version

Apache Maven 3.2.1 (r801777; 2009-08-07 00:46:01+0530)

Java version: 1.6.0_65

Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Default locale: en_US, platform encoding: MacRoman

OS name: “mac os x” version: “10.9.2” arch: “x86_64” Family: “mac”

End of Text!😀

3 comments

  1. I like the helpful information you provide in your articles.
    I will bookmark your blog and check again here frequently.
    I am quite sure I will learn many new stuff right here!
    Best of luck for the next!

  2. Please correct the code:
    export JAVA_HOME = /usr/libexec/java_home

    it must not contain spaces near “=”, it should look like this:
    export JAVA_HOME=/usr/libexec/java_home

    And one remark is that, which you should probably explain on the very beginning, that “/usr/libexec/java_home” is not the java home path but it is a command to be executed to get the right path.

    And the last remark:
    you may execute the above command and specify the java version if you have more than one Java, for example:
    export JAVA_HOME = $(/usr/libexec/java_home -v 1.7)
    or
    export JAVA_HOME = `/usr/libexec/java_home -v 1.7` (be careful here, it isn’t normal apostrophe it is grave accent – the one under tilde key)

    Regards,
    Piotr

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s