从命令行通过 ant 构建 java eclipse 项目时出错

发布于 2024-11-05 14:37:24 字数 915 浏览 0 评论 0原文

我正在尝试通过命令行使用 ant 构建一个 Eclipse 项目。当我在 java 中运行 build.xml 文件时效果很好,但是当我 cd 到项目目录(build.xml 所在的位置)并运行 ant -f build.xml 时,出现以下错误msg:

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
Buildfile: build.xml

clean:
   [delete] Deleting directory /home/adam/workspace/pfaat/classes

build:
    [mkdir] Created dir: /home/adam/workspace/pfaat/classes
    [javac] Compiling 502 source files to /home/adam/workspace/pfaat/classes

BUILD FAILED
/home/adam/workspace/pfaat/build.xml:86: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"

Total time: 0 seconds

有没有办法让我从命令行指定编译器而不更改 build.xml?再说一遍,当我用 eclipse 运行它时,它工作得很好,而且我在 eclipse 或 ant 手册中没有找到任何表明它不会工作的内容。顺便说一句,我运行的是 ubuntu 10.04。非常感谢您抽出时间。 亚当

I'm trying to build an eclipse project with ant via the command line. The build.xml file works great when I run it in java, but when I cd to the project directory(where build.xml is located) and run ant -f build.xml I get the following error msg:

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
Buildfile: build.xml

clean:
   [delete] Deleting directory /home/adam/workspace/pfaat/classes

build:
    [mkdir] Created dir: /home/adam/workspace/pfaat/classes
    [javac] Compiling 502 source files to /home/adam/workspace/pfaat/classes

BUILD FAILED
/home/adam/workspace/pfaat/build.xml:86: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"

Total time: 0 seconds

Is there a way for me to specify the compiler from the command line w/o changing the build.xml? Again, it works fine when I run it with eclipse, and I haven't found anything in the eclipse or ant manual that should suggest it wouldn't. BTW, I'm running ubuntu 10.04. Thank you very much for your time.
Adam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百善笑为先 2024-11-12 14:37:24

设置指向tools.jar的PATH确保它有tools.jar文件

使用

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

set PATH that points to tools.jar make sure that it have tools.jar file

use

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
归属感 2024-11-12 14:37:24

您的 JAVA HOME 路径设置为您的 JRE。 Ant 需要 JDK 才能从命令行工作。

Your JAVA HOME path is set to your JRE. Ant needs JDK to work from command line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文