maven ignoring jenv settings


Java Problem Overview

I had OSX with Java 1.6 installed, and I just installed jenv along with Java 1.7:

$ jenv local '1.7'
$ jenv versions
* 1.7 (set by /Users/me/workspace/.java-version)

jenv is doing its job, with $ java -version always working, showing 1.6 when I've set it to 1.6, and 1.7 when I've set it to 1.7:

$ java -version
java version "1.7.0_79"                    <--------------------------------- YAY!!
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

... but maven is ignoring my settings:

$ mvn -version
Apache Maven 3.0.2 (r1056850; 2011-01-08 19:58:10-0500)
Java version: 1.6.0_65, vendor: Apple Inc. <--------------------------------- BAH!!
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.8.5", arch: "x86_64", family: "mac"

I found this SO question where the guy just needed to hardcode his JAVA_HOME inside .mavenrc, but I don't want mine hard-coded (thus jenv!), and I don't have a ~/.mavenrc, nor an /etc/mavenrc.

The version it's using seems to be from whatever's first on the /usr/libexec/java_home output, so in the short term I was able to get 1.6 back again by tweaking 1.7's Info.plist file (from this SO post), but that just means I get 1.6 instead of 1.7.

Any ideas?

Java Solutions

Solution 1 - Java

You need to install the jenv maven plugin, try the following command and reload your shell:

>jenv enable-plugin maven

Solution 2 - Java

I had a similar problem. I got things running by prefixing all command with jenv exec:

jenv exec mvn -version

Solution 3 - Java

Now, there's a new option how to set JAVA_HOME via jenv export plugin:

jenv enable-plugin export


Solution 4 - Java

If you have enabled the maven and export plugins, and still have problems, check that you don't have a ~/.mavenrc file which is setting JAVA_HOME.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioninanutshellusView Question on Stackoverflow
Solution 1 - JavatenfourtyView Answer on Stackoverflow
Solution 2 - JavaaautioView Answer on Stackoverflow
Solution 3 - JavaJuraj MartinkaView Answer on Stackoverflow
Solution 4 - JavatgdaviesView Answer on Stackoverflow