Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid target release when building with maven

I recently upgrade my machine to the latest version of java 6, and keep getting this error when building the project. Does anyone what this means?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project
 biz.minaret: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.6.0_45
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options

Part of my pom looks like this

  <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.plugin.version}</version>
            <configuration>
                <source>1.6.0_45</source>
                <target>1.6.0_45</target>
                <encoding>UTF-8</encoding>
            </configuration>
  </plugin>

My JAVA_HOME is properly set:

PS C:\Users\me\Documents\m

Documents\myproject> java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)>

And:

Documents\myproject> javac -version
javac 1.6.0_45
like image 856
0x56794E Avatar asked Sep 05 '13 01:09

0x56794E


People also ask

What does invalid target release 17 mean in Maven?

The error is invalid target release: 17 - that means the project’s Java version is 17 but Maven is running under lower JDK version. To see the version of JDK that runs Maven, type mvn -v and you will see something like this: Maven home: g:\apache-maven-3.6.3\bin\..

What does invalid target release 1 9 mean?

Invalid Target Release: 1.9. This error will come if your Maven compiler plugin has <target>1.9</target> but the JAVA_HOME variable in your machine is referring to a Java version that is lower than JDK 1.9, e.g. JDK 1.8 or JDK 1.7.

Why is my Maven build not running?

You may encounter the following error when running a Maven build: This problem is due to the fact that the environment variable JAVA_HOME and the target property of the maven-compiler-plugin point to a different JDK versions. The easy solution will be to fill JAVA_HOME with the correct value.

How to fix Java 7 not compiled in Maven?

Because Java 7 was not required for my project, I just had to change the Maven compile plugin as follows: But if you have to build your Java project with JDK 1.7, then just install and update your JAVA_HOME variable and this error will go away. This solution is really nice as you can solve the problem immediately.


1 Answers

You should use things like 1.6 or 1.7 without build numbers.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>${maven.compiler.plugin.version}</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <encoding>UTF-8</encoding>
  </configuration>
</plugin>

The encoding part should be solved by using the following properties:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

After you have defined that you can simplyfied the above configuration to the following

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>${maven.compiler.plugin.version}</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>
like image 111
khmarbaise Avatar answered Oct 24 '22 09:10

khmarbaise