Maven: Fatal error compiling: invalid target release: 1.8
Solution 1
Check the java and Javac version - My Java version was 1.8.0_51
$ java -version
java version "1.8.0_51"
But javac version was pointing to old jdk 1.7.0_67
$ javac -version
javac 1.7.0_67
There are couple of thing which we should try -
Ensure that symbolic link is pointing to correct jdk. If not, remove existing link and create new one for your jdk
cd /System/Library/Frameworks/JavaVM.framework/Versions/ rm CurrentJDK ln -s /Library/Java/JavaVirtualMachines/<jdk version>.jdk/Contents/ CurrentJDK
In /Library/Java/Extension, i had a tools.jar. I believe, this was from old jdk.
cd /Library/Java/Extensions -rw-r--r-- 1 root admin 15286304 Jan 14 2015 tools.jar
Remove this
sudo rm -rf /Library/Java/Extensions
point 2 did the trick for me :)
Solution 2
Sometimes this problem is related to a JAVA_HOME
used by maven.
- In my particular case I tried to start an
install
target and had an exact the subj message. - Then I just tried an
mvn -version
command and I realized that it uses jdk7 - Then I run in a console
set JAVA_HOME=C:\Java\jdk8
(my jdk path, so your own could be different) - Then typed
mvn clean install test
and it worked just fine at last
Good luck!
Solution 3
Same issue here, but I was using run configurations inside Eclipse when maven kept throwing this error. Fixed by setting the right JDK version here:
Pankaj
Updated on July 09, 2022Comments
-
Pankaj almost 2 years
We just upgraded the project from
jdk 1.6
tojdk 1.8
. While building the project in my machine, i'm getting following error.[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project exception: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
Here is the maven compiler plugin which is been used
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin>
I looked at the many post and most of them were related with not having the correct version configured for java_home. I verified all of these aspects and couldn't find any of them alarming.
Java version -
qadeersmsiphone:main pdubey$ java -version java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Maven Version -
qadeersmsiphone:main pdubey$ mvn -version Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700) Maven home: /usr/share/maven Java version: 1.8.0_51, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"
and I checked that while building the project maven uses jdk 1.8
qadeersmsiphone:main pdubey$ mvn install -debug Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700) Maven home: /usr/share/maven Java version: 1.8.0_51, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac" [INFO] Error stacktraces are turned on. [DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml [DEBUG] Reading user settings from /Users/pdubey/.m2/settings.xml [DEBUG] Using local repository at /Users/pdubey/.m2/repository [DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pdubey/.m2/repository [INFO] Scanning for projects...
UPDATE: I could get it working by removing the maven-compiler-plugin in pom file (Ideally, i don't want to do this). And i also observed that even if i remove this plugin, maven by default downloads the 3.3 version of compiler plugin in my local repo. I'm not sure what's wrong in this plugin although source and target appears to be correct.
-
circuitry about 8 yearsThank you, finally! Point 2 solved this for me as well.
-
papanito over 4 yearsThat was it for me
mvn
used another version. If you are using powershell run this:$env:JAVA_HOME="C:\java\jdk8