2011-02-10 42 views
16

问题Ant构建问题Ant构建无效的目标版本

[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 

蚂蚁的源和目标1.6 EN变量路径JDK 1.6

+2

,有人知道决定使用哪种Java版本,当蚂蚁着眼于JAVA_HOME变量,它可能是有用的。 – fejd 2012-01-10 16:17:31

回答

26

您使用编译器不能用-target 1.6器(javac编译:无效的目标版本:1.6)。你确定你使用JDK 1.6吗?也许一个JDK 1.5被安装并被ant使用。检查中使用的Java版本添加下面一行到你的目标(开头):

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

它输出由蚂蚁使用的Java版本。

您可以设置编译器使用不同的Java版本。你必须用叉子属性使用外部的javac,并指定要哪一个:

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

阅读javac-task的文档的详细信息。

+0

是的,它使用1.5从哪里它挑我的应用程序需要1.5和1.6,但我想蚂蚁选择1.6我怎么能改变它 – Gopal 2011-02-10 12:40:55

+0

我添加了一个可能性来指定使用哪个Java编译器。 – Mnementh 2011-02-10 12:54:06

13

也许需要做蚂蚁建设者符合您的JRE。

Windows->Preferences->Ant->Runtime->Classpath->Global Entries,加<*your jre home*>/lib/tools.jar和移动它。

12

此外,您可以在您的项目在Ant视图中右键单击并选择Run As ...>外部工具配置...在JRE选项卡中,选择正确的运行时JRE。

0

是的,这是一个古老的一个,但在工作中碰上了,但没有找到任何地方记录尚未解决...

虽然我也碰到这个使用Ant来了,这其实似乎没有有什么用蚂蚁 - 那里似乎已经有些破碎的JDK构建出有:

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> 
... 

凡为其他1.6构建的样子:

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 

所以溶胶ution是升级JDK。

0

右键单击ant构建文件;运行为; Ant Build ...; JRE选项卡;并尝试设置一个单独的JRE到你想要的。尽管我只安装了一个JRE,但对我来说这仍然有效,Eclipse似乎记住了旧版本的幽灵。