2011-02-10 77 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似乎記住了舊版本的幽靈。