感谢大家的帮助!
我在尝试使用Ant编译项目时遇到错误,它声称“[javac] javac:无效的目标版本:7”并导致构建失败 .
我在Mac OSX Mavericks机器上运行javac版本1.7.0_40 . Ant版本:Apache Ant(TM)版本1.8.3于2012年2月26日编译
只有在尝试使用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.
有任何想法吗?非常感谢帮助 .
2 回答
问题是Ant正在我的计算机上查看Java 1.6安装(我没有意识到存在),并且由于我的$ JAVA_HOME变量未设置,因此无法找到1.7安装 . 我通过在.bash_profile文件中添加以下行来添加$ JAVA_HOME变量:
这纠正了问题,项目建成成功 .
我意识到它实际上告诉了我最初在我的Ant输出顶部的Java版本,但我以前没有注意到它:
一些其他注释可能对有类似问题的用户有所帮助:
According to this,如果"fork"字段设置为yes,Ant将仅使用build-common.xml文件的javac部分的"executable"字段中的值 . fork默认为"no"(如果未列出),因此如果不添加它并将其设置为"yes",则将忽略"executable"值 .
在Mac上,可以通过/ usr / bin / javac访问正确的javac可执行文件 . 在命令行上,您可以运行
找到命令行正在执行的文件的路径,当然
找到它的版本号 . 如上所述,Ant不会在命令行PATH中查看javac,而是在JAVA_HOME中查看 .
感谢大家的帮助!
我的解决方案是更改所有project.properties文件
至