【发布时间】:2014-03-08 13:36:14
【问题描述】:
感谢大家的帮助!
我在尝试使用 Ant 编译项目时遇到错误,它声称“[javac] javac: invalid target release: 7”并导致构建失败。
我在 Mac OSX Mavericks 机器上运行 javac 版本 1.7.0_40。 Ant 版本:2012 年 2 月 26 日编译的 Apache Ant(TM) 版本 1.8.3
只有在尝试使用 Ant 进行编译时才会出现问题。在命令行使用 javac 编译项目中的单个文件可以正常工作(使用以下命令):
javac -d /Users/username/git/appinventor-sources/appinventor/common/build/classes/CommonUtils -classpath /Users/username/git/appinventor-sources/appinventor/common/build/classes/CommonUtils:/Users/username/git/appinventor-sources/appinventor/lib/guava/guava-14.0.1.jar -target 7 -encoding utf-8 -g:lines,vars,source -source 7 common/src/com/google/appinventor/common/utils/*
build-common.xml 文件为 javac 指定:
<attribute name="source" default="7"/>
<attribute name="target" default="7"/>
相同的构建文件对其他人来说工作得很好,可以在以下位置找到: https://github.com/cdlockard/appinventor-sources/blob/master/appinventor/build-common.xml
阅读this 后,我检查了我机器上的早期Java 版本,但没有找到。
根据this question,我添加了
executable="/usr/bin/javac"
到 build-common.xml 文件,以确保它找到了正确的 Java 编译器,但错误仍在继续。
命令行输出如下:
init:
CommonUtils:
[javac] Compiling 1 source file to /Users/username/git/appinventor-sources/appinventor/common/build/classes/CommonUtils
[javac] javac: invalid target release: 7
[javac] Usage: javac <options> <source files>
[javac] use -help for a list of possible options
BUILD FAILED
/Users/username/git/appinventor-sources/appinventor/build.xml:16: The following error occurred while executing this line:
/Users/username/git/appinventor-sources/appinventor/build-common.xml:318: The following error occurred while executing this line:
/Users/username/git/appinventor-sources/appinventor/common/build.xml:42: The following error occurred while executing this line:
/Users/username/git/appinventor-sources/appinventor/build-common.xml:120: Compile failed; see the compiler error output for details.
以详细方式运行 ant 会产生以下详细信息:
[javac] Compiling 1 source file to /Users/username/git/appinventor-sources/appinventor/common/build/classes/CommonUtils
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] '/Users/username/git/appinventor-sources/appinventor/common/build/classes/CommonUtils'
[javac] '-classpath'
[javac] '/Users/username/git/appinventor-sources/appinventor/common/build/classes/CommonUtils:/Users/username/git/appinventor-sources/appinventor/lib/guava/guava-14.0.1.jar'
[javac] '-target'
[javac] '7'
[javac] '-encoding'
[javac] 'utf-8'
[javac] '-g:lines,vars,source'
[javac] '-verbose'
[javac] '-source'
[javac] '7'
[javac]
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
[javac] File to be compiled:
[javac] /Users/username/git/appinventor-sources/appinventor/common/src/com/google/appinventor/common/utils/package-info.java
[javac] javac: invalid target release: 7
[javac] Usage: javac <options> <source files>
[javac] use -help for a list of possible options
[ant] Exiting /Users/username/git/appinventor-sources/appinventor/common/build.xml.
有什么想法吗?非常感谢您的帮助。
【问题讨论】:
-
你不是说
1.7吗? (相对于7)。 -
其实
7是合法的。我怀疑问题出在ant使用 java6 jdk -
2.7 出来的时候会很有趣。 50 年后。
-
问题是 Ant 正在查看我计算机上的 Java 1.6 安装,并且由于我的 $JAVA_HOME 变量没有设置,它无法找到 1.7 安装。我通过将以下行添加到我的 .bash_profile 文件中添加了 $JAVA_HOME 变量: export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home' 这解决了问题。感谢大家的帮助!
-
@clock,很高兴你知道了。我看你是新来的。请为未来的用户回答您自己的问题。你知道为什么它在命令行中有效,但在 ant 中无效吗?