Can't get Maven to recognize Java 1.8


I can't seem to get Maven to work with Java 1.8. Using 1.8 as the target gives the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
(default-compile) on project csaro: Fatal error compiling: invalid target
release: 1.8 -> [Help 1]

The reason for the error is obvious: Maven is not using the correct Java version:

$ mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T07:51:42-06:00)
Maven home: /usr/local/Cellar/maven/3.2.2/libexec
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"

But the installed version of Java should be 1.8:

$ java -version
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b22)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b21, mixed mode)

and set JAVA_HOME:

$ echo $JAVA_HOME

I also tried the command (create ) here . I've tried restarting the computer a few times and verified that the env var is set correctly (set in ).mavenrc.bash_profile

Maven is installed with Homebrew.

Java 1.8 works fine in Eclipse (using m2e). I just can't get Maven to work on the command line.


It turned out that I had a forgotten file ~/.mavenrcset to the value of JAVA_HOME.

For future readers, please check the following locations for possible overridden locations JAVA_HOME(in ascending order of preference):

  • ~/.bash_profile
  • ~/.bash_login
  • ~/.bashrc
  • ~/.profile
  • /etc/mavenrc
  • ~/.mavenrc