Invalid target release when building with maven
Asked Answered
P

2

6

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
Prepositor answered 5/9, 2013 at 1:48 Comment(7)
you are looking for JDK 1.6.0_45, can you type javac -version and see what version you haveGallia
Update the JAVA_HOME and classpath pointing to the latest version. If all else fails and you are still on 1.6 and are not making an application targeting a specific release of java (45 in your case), just edit the source and target tags to 1.6Spay
just updated my questionPrepositor
Source and target should be 1.6.Gardell
@DaveNewton could you explain why?Prepositor
@abcXYZ Because that parameter mirrors the javac source and target flags, which accepts things like 1.6/6, 1.7/7, and not build numbers. docs.oracle.com/javase/7/docs/technotes/tools/windows/…Gardell
aaah. should've known! thank you!!!Prepositor
E
5

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>
Elwoodelwyn answered 5/9, 2013 at 5:48 Comment(0)
C
0

Instead of modifying the pom.xml file with specific source and target version in configuration tab, just specify it via an environment variable.

Use this command:

mvn clean install -Denv.JAVA_7_HOME=/usr/lib/jvm/java-7-openjdk-amd64/

This will solve the error definitely.

Thanks,

Prasad

Complimentary answered 13/4, 2018 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.