Can't get Maven to recognize Java 1.8

Solution 1:

For me the issue was that when I installed from jdk-8u25-macosx-x64.dmg the installation did not update the /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK directory link to the new 1.8 JDK. This may not have been the issue of the original question but it was the solution for me when I encountered the same error message.

I don't know why the installer doesn't link it and to make matters more confusing, the path is different depending on whether you installed it from Oracle or Apple. See Mac OS X 10.6.7 Java Path Current JDK confusing

I did the following to fix my environment

cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo rm CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/<installed_jdk_version>.jdk/Contents CurrentJDK

Solution 2:

It turns out that I had a forgotten ~/.mavenrc file that had set the value of JAVA_HOME.

For future readers, check the following locations for places that may override JAVA_HOME (in ascending order of precedence):

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

Solution 3:

The solution which worked for me:

In Eclipse, I had a wrong run configuration in my Maven build. Go to

Run Configurations -> JRE [Tab]

and set the runtime to Java 8.

Solution 4:

I ran into the same problem on my CentOS 6.5 system.

java -version returned a Java 8 version, but javac -version returned a Java 7 version.

I had to run the following commands to get all kinds of Java-related symlinks point to my JDK 8 installation:

sudo alternatives --config java
sudo alternatives --config javac
sudo alternatives --config jre_openjdk
sudo alternatives --config java_sdk_openjdk