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:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle

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.

References:
http://stackoverflow.com/questions/28044461/javac-invalid-target-release-1-8-on-mac-when-executing-maven-command

http://tecadmin.net/install-oracle-java-8-jdk-8-ubuntu-via-ppa/#

Advertisements

About Ronnie Diaz

Ronnie Diaz is an enterprise software engineer responsible for front-end and back-end development for companies in many industries. Heavily involved in cloud development, online retail, e-commerce and electronic ordering, fulfillment and customer relational systems.

Posted on November 9, 2015, in Programming & Development and tagged , , , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: