我正在尝试通过命令行使用 ant 构建一个 Eclipse 项目。当我在 java 中运行 build.xml 文件时效果很好,但是当我 cd 到项目目录(build.xml 所在的位置)并运行 ant -f build.xml
时,出现以下错误消息:
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。非常感谢您的宝贵时间。 亚当
最佳答案
设置指向tools.jar的PATH,确保它有tools.jar
文件
使用
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
关于java - 从命令行通过 ant 构建 java eclipse 项目时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5892384/