problem in ant build invalid target release

problem in ant build

[javac] Compiling 86 source files to F:\XXX\classes
    [javac] javac: invalid target release: 1.6
    [javac] Usage: javac <options> <source files>
    [javac] where possible options include:
    [javac]   -g                         Generate all debugging info
    [javac]   -g:none                    Generate no debugging info
    [javac]   -g:{lines,vars,source}     Generate only some debugging info
    [javac]   -nowarn                    Generate no warnings
    [javac]   -verbose                   Output messages about what the compiler is doing
    [javac]   -deprecation               Output source locations where deprecated APIs are used
    [javac]   -classpath <path>          Specify where to find user class files
    [javac]   -cp <path>                 Specify where to find user class files
    [javac]   -sourcepath <path>         Specify where to find input source files
    [javac]   -bootclasspath <path>      Override location of bootstrap class files
    [javac]   -extdirs <dirs>            Override location of installed extensions
    [javac]   -endorseddirs <dirs>       Override location of endorsed standards path
    [javac]   -d <directory>             Specify where to place generated class files
    [javac]   -encoding <encoding>       Specify character encoding used by source files
    [javac]   -source <release>          Provide source compatibility with specified release
    [javac]   -target <release>          Generate class files for specific VM version
    [javac]   -version                   Version information
    [javac]   -help                      Print a synopsis of standard options
    [javac]   -X                         Print a synopsis of nonstandard options
    [javac]   -J<flag>                   Pass <flag> directly to the runtime system


BUILD FAILED

ant source and target to 1.6 en variable path to jdk 1.6

Answers


You use a compiler that cannot compile with -target 1.6 (javac: invalid target release: 1.6). Are you sure you use the JDK 1.6? Maybe a JDK 1.5 is installed and used by ant. Check the used Java-version with adding following line to your target (at the beginning):

<echo message="Using Java version ${ant.java.version}."/>

It outputs the Java-version used by Ant.

You can set the compiler to use a different Java-version. You have to use the fork-attribute to use an external javac and specify which one you want:

<javac srcdir="${src}"
         destdir="${build}"
         fork="yes"
         executable="/opt/java/jdk1.6/bin/javac"
  />

Read the documentation of the javac-task for details.


Maybe need to make the ant builder match your jre.

At Windows->Preferences->Ant->Runtime->Classpath->Global Entries, add <*your jre home*>/lib/tools.jar and move it up.


Also, you can right-click on your project in your Ant view and choose Run As... > External Tools Configuration... In the JRE tab, select the correct Runtime JRE.


Yes, this is an old one, but came across at work and could not find a solution documented anywhere yet...

Even though I too came across this using Ant, it in fact does not seem to have anything to do with Ant - there seem to have been some broken JDK builds out there:

C:\>%JAVA_HOME%\bin\javac -version
javac 1.6.0_21
javac: no source files
Usage: javac <options> <source files>
...

C:\>%JAVA_HOME%\bin\javac -target 1.6
javac: invalid target release: 1.6
Usage: javac <options> <source files>
...

Where as another 1.6 build looks like:

C:\>set JAVA_HOME=C:\Progra~1\Java\jdk1.6.0_45

C:\>%JAVA_HOME%\bin\javac -version
javac 1.6.0_45

C:\>%JAVA_HOME%\bin\javac -target 1.6
javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options

So the solution is to upgrade JDK.


Right click on ant build file; Run As; Ant Build...; JRE tab; and try setting a separate JRE to the one you want. That worked for me, even though I only have one JRE installed, Eclipse seemed to be remembering the ghost of an old one.


Need Your Help

How to disable Google Chrome auto update?

google-chrome auto-update

Does anyone know how to disable Google Chrome for being automatic update itself, it cause my web application always change?