ant构建无效目标释放的问题

Gop*_*pal 17 java 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
Run Code Online (Sandbox Code Playgroud)

ant源和目标1.6到jdk 1.6的可变路径

Mne*_*nth 27

您使用无法编译的编译器-target 1.6(javac:无效的目标版本:1.6).你确定使用JDK 1.6吗?也许安装并使用了JDK 1.5.检查使用过的Java版本,并在目标中添加以下行(在开头):

<echo message="Using Java version ${ant.java.version}."/>
Run Code Online (Sandbox Code Playgroud)

它输出Ant使用的Java版本.

您可以将编译器设置为使用其他Java版本.您必须使用fork-attribute来使用外部javac并指定您想要的那个:

<javac srcdir="${src}"
         destdir="${build}"
         fork="yes"
         executable="/opt/java/jdk1.6/bin/javac"
  />
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请阅读javac-task的文档.

  • 我给了你一个关于echo标签的upvote,但它回应1.7并且下一行是错误"无效目标版本1.7"任何想法? (2认同)

小智 13

也许需要让蚂蚁生成器匹配你的jre.

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


小智 13

此外,您可以在Ant视图中右键单击项目,然后选择Run As ...> External Tools Configuration ...在JRE选项卡中,选择正确的Runtime JRE.