problem in ant build invalid target release

前端 未结 5 1891
执念已碎
执念已碎 2021-01-17 10:41

problem in ant build

[javac] Compiling 86 source files to F:\\XXX\\classes
    [javac] javac: invalid target release: 1.6
    [javac] Usage: javac 

        
相关标签:
5条回答
  • 2021-01-17 11:29

    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.

    0 讨论(0)
  • 2021-01-17 11:34

    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.

    0 讨论(0)
  • 2021-01-17 11:42

    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.

    0 讨论(0)
  • 2021-01-17 11:43

    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.

    0 讨论(0)
  • 2021-01-17 11:43

    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.

    0 讨论(0)
提交回复
热议问题