javac invalid target release maven ant intellij netbeans eclipse
You may see the following error when running maven or ant command or from intellij:
javac: invalid target release: 1.8
This occurs because you are running a build target for a version of java that you do not have set as your default in JAVA_HOME.
If you do not have java 8 installed, in ubuntu this is as simple as:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
This is similar in other flavors of linux, simply add the official oracle repo and install. Installation in Windows requires browsing to the JDK/JRE pages on Oracle and downloading/installing. Avoid OpenJDK. This is outside the context of this blog post, but you can google “openjdk vs oracle jdk performance” to learn more.
If you see this error in an IDE such as intellij, netbeans or eclipse, this can be fixed by setting the java compile in your Settings to Java 8. E.g. if the error above said 1.9, change this to Java 9.
If you are upgrading from 7 to 8, the last oracle install step when installing the package should set JAVA_HOME:
(ubuntu) sudo apt-get install oracle-java8-set-default
If the above install command or corresponding install script on your system does not work, to fix you can also manually set JAVA_HOME, such as:
echo the current $JAVA_HOME and the new oracle java home should be alongside it.
In my scenario I actually ran the oracle provided install script but it failed to set the java home correctly so I still had to do this manually.