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

ant构建中的问题

[javac] Compiling 86 source files to F:\XXX\classes [javac] javac: invalid target release: 1.6 [javac] Usage: javac   [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  Specify where to find user class files [javac] -cp  Specify where to find user class files [javac] -sourcepath  Specify where to find input source files [javac] -bootclasspath  Override location of bootstrap class files [javac] -extdirs  Override location of installed extensions [javac] -endorseddirs  Override location of endorsed standards path [javac] -d  Specify where to place generated class files [javac] -encoding  Specify character encoding used by source files [javac] -source  Provide source compatibility with specified release [javac] -target  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 Pass  directly to the runtime system BUILD FAILED 

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

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

  

它输出Ant使用的Java版本。

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

  

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

也许需要让ant生成器匹配你的jre。

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

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

是的,这是一个旧版本,但是在工作中遇到并且无法在任何地方找到解决方案……

虽然我也使用Ant来实现这一点,但实际上它似乎与Ant没有任何关系 – 似乎有一些破坏的JDK构建:

 C:\>%JAVA_HOME%\bin\javac -version javac 1.6.0_21 javac: no source files Usage: javac   ... C:\>%JAVA_HOME%\bin\javac -target 1.6 javac: invalid target release: 1.6 Usage: javac   ... 

另外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   use -help for a list of possible options 

所以解决方案是升级JDK。

右键单击ant build文件; 跑步; Ant Build ……; JRE标签; 并尝试将单独的JRE设置为您想要的JRE。 这对我有用,即使我只安装了一个JRE,Eclipse似乎还记得旧版的幽灵。