首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >,"[javac] javac:无效的目标发布: 7“

,"[javac] javac:无效的目标发布: 7“
EN

Stack Overflow用户
提问于 2014-02-11 00:01:57
回答 2查看 18K关注 0票数 4

更新:见这里的决议。

感谢大家的帮助!

当我试图用Ant编译一个项目时,我遇到了一个错误,它声称"javac javac:无效的目标发布: 7“并导致构建失败。

我正在Mac小牛机上运行javac版本的1.7.0_40。Ant版本: Apache (TM)版本1.8.3,2012年2月26日编译

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

代码语言:javascript
复制
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:

代码语言:javascript
复制
<attribute name="source" default="7"/>
<attribute name="target" default="7"/>

相同的构建文件对其他构建文件运行良好,可以在:https://github.com/cdlockard/appinventor-sources/blob/master/appinventor/build-common.xml找到。

在阅读了之后,我在我的机器上检查了早期的Java版本,但是没有找到任何版本。

每一个这个问题,我添加了

代码语言:javascript
复制
executable="/usr/bin/javac"

文件,以确保它找到了正确的Java编译器,但错误仍在继续。

命令行输出如下:

代码语言:javascript
复制
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获得了以下详细信息:

代码语言:javascript
复制
[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.

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-13 01:00:34

问题是Ant正在查看我的计算机上的Java1.6安装(我还没有意识到这一点),而且由于没有设置我的$JAVA_HOME变量,所以它无法找到1.7install。我向我的$JAVA_HOME文件中添加了以下行,从而添加了一个.bash_profile变量:

代码语言:javascript
复制
export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home'

这就纠正了问题,并成功地建造了该项目。

我意识到它实际上告诉了我最初在Ant输出顶部的Java版本,但我以前没有注意到:

代码语言:javascript
复制
Detected Java version: 1.6 in: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

一些可能有助于有类似问题的用户的补充说明:

-如果“根据这个”字段被设置为是的话,Ant只会在buil-Common.xml文件的javac部分的“可执行”字段中使用该值。如果未列出叉子,默认为"no“,因此如果不添加它并将其设置为”是“,则”可执行“值将被忽略。

-On a Mac,您可以通过/usr/bin/javac实现正确的javac可执行文件。在命令行上,可以运行

代码语言:javascript
复制
which javac

查找在命令行执行的文件的路径,当然还有

代码语言:javascript
复制
javac -version

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

感谢大家的帮助!

票数 6
EN

Stack Overflow用户

发布于 2014-07-29 22:51:03

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

代码语言:javascript
复制
javac.source=1.8
javac.target=1.8

代码语言:javascript
复制
javac.source=1.7
javac.target=1.7
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21690464

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档