I can't seem to be able to get Maven to use Java 1.8. Using 1.8 as the target turns up 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 cause of the error is obvious enough: Maven isn't using the right version of Java:
$ 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 JAVA_HOME is set:
$ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
I also tried the command here (which creates mavenrc
). I've tried restarting the computer several times, and have verified that the env var is correctly set (it's set in .bash_profile
).
Maven was installed with Homebrew.
Java 1.8 is working fine in Eclipse (which is using m2e). I just can't get Maven to work on the command line.
2.1. The Maven compiler accepts this command with –target and –source versions. If we want to use the Java 8 language features, the –source should be set to 1.8. Also, for the compiled classes to be compatible with JVM 1.8, the –target value should be 1.8. The default value for both of them is the 1.6 version.
In short – 8 is product version number and 1.8 is the developer version number (or internal version number). The product is the same, JDK 8, anyways.
Maven Configuration The Maven tool uses JDK version 11.0.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With