Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“Ant构建失败”;[javac]javac:目标版本无效:7“;_Java_Ant_Javac - Fatal编程技术网

“Ant构建失败”;[javac]javac:目标版本无效:7“;

“Ant构建失败”;[javac]javac:目标版本无效:7“;,java,ant,javac,Java,Ant,Javac,更新: 谢谢大家的帮助 我在尝试用Ant编译项目时遇到了一个错误,它声称“[javac]javac:invalid target release:7”,并导致构建失败 我正在MacOSXMavericks机器上运行javac版本1.7.040。Ant版本:ApacheAnt(TM)版本1.8.3于2012年2月26日编译 只有在尝试使用Ant编译时,才会出现问题。在命令行使用javac编译项目中的各个文件可以正常工作(使用以下命令): build-common.xml文件为javac指定:

更新:

谢谢大家的帮助


我在尝试用Ant编译项目时遇到了一个错误,它声称“[javac]javac:invalid target release:7”,并导致构建失败

我正在MacOSXMavericks机器上运行javac版本1.7.040。Ant版本:ApacheAnt(TM)版本1.8.3于2012年2月26日编译

只有在尝试使用Ant编译时,才会出现问题。在命令行使用javac编译项目中的各个文件可以正常工作(使用以下命令):

build-common.xml文件为javac指定:

<attribute name="source" default="7"/>
<attribute name="target" default="7"/>
到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.
init:
共性:
[javac]将1个源文件编译为/Users/username/git/appinventor sources/appinventor/common/build/classes/CommonUtils
[javac]javac:目标版本无效:7
[javac]用法:javac
[javac]使用-help获取可能选项的列表
构建失败
/Users/username/git/appinventor sources/appinventor/build.xml:16:执行此行时发生以下错误:
/Users/username/git/appinventor sources/appinventor/build common.xml:318:执行此行时发生以下错误:
/Users/username/git/appinventor sources/appinventor/common/build.xml:42:执行此行时发生以下错误:
/Users/username/git/appinventor sources/appinventor/build common.xml:120:编译失败;有关详细信息,请参阅编译器错误输出。
在verbose中运行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.
[javac]将1个源文件编译为/Users/username/git/appinventor sources/appinventor/common/build/classes/CommonUtils
[javac]使用现代编译器
[javac]编译参数:
[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]“-编码”
[javac]“utf-8”
[javac]'-g:line,vars,source'
[javac]'-verbose'
[javac]'-source'
[javac]“7”
[javac]
[javac]可执行文件和参数周围的字符是
[javac]不是命令的一部分。
要编译的[javac]文件:
[javac]/Users/username/git/appinventor sources/appinventor/common/src/com/google/appinventor/common/utils/package-info.java
[javac]javac:目标版本无效:7
[javac]用法:javac
[javac]使用-help获取可能选项的列表
[ant]正在退出/Users/username/git/appinventor sources/appinventor/common/build.xml。

有什么想法吗?非常感谢您的帮助。

问题是Ant正在我的计算机上安装Java 1.6(我没有意识到它的存在),并且由于我的$Java_HOME变量没有设置,所以它无法找到1.7安装。通过将以下行添加到.bash\u概要文件中,我添加了$JAVA\u HOME变量:

export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home'
这纠正了问题,项目建设成功

我意识到它最初在我的Ant输出的最顶端通知了我Java版本,但我以前没有注意到:

Detected Java version: 1.6 in: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
一些可能对有类似问题的用户有用的附加说明:

-,如果“fork”字段设置为yes,Ant将只使用build-common.xml文件javac部分的“executable”字段中的值。如果未列出,fork默认为“no”,因此如果不添加它并将其设置为“yes”,则“executable”值将被忽略

-在Mac上,可以通过/usr/bin/javac访问正确的javac可执行文件。在命令行上,可以运行

which javac
找到在命令行执行的文件的路径,当然

javac -version
查找其版本号。如上所述,Ant不会查看命令行路径中的javac,而是查看JAVA_HOME


谢谢大家的帮助

我的解决方案是更改所有project.properties文件


你是说
1.7
?(与
7
相反)。实际上,
7
是合法的。我怀疑问题在于ant如何选择Java6JDK,这在2.7发布后会很有趣。50年后,问题是Ant在我的计算机上安装了Java1.6,由于没有设置$Java_HOME变量,所以找不到1.7安装。我通过在.bash_概要文件中添加以下行添加了$JAVA_HOME变量:export JAVA_HOME='/Library/JAVA/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/HOME'这纠正了问题。谢谢大家的帮助@时钟,很高兴你找到了。我看你是新来的。请回答您自己的问题,以供将来的用户使用。你知道为什么它在命令行工作而在ant中不工作吗?我也有同样的问题。这也是唯一的解决办法。
which javac
javac -version
javac.source=1.8
javac.target=1.8
javac.source=1.7
javac.target=1.7