【发布时间】:2011-12-02 17:35:13
【问题描述】:
我曾尝试以编程方式调用 Ant,但遇到此错误
线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/AntMain
我尝试使用控制台单独运行 build.xml,并在作为 ant build 运行的 eclipse 中右键单击它。它运行没有问题。
我的样本蚂蚁测试课
public class AntTest {
public static void main(String[] args) {
File buildFile = new File("build.xml");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
}
}
我的示例 build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="testproject" default="test" basedir=".">
<target name="test">
<echo message="Hello World" />
</target>
</project>
我错过了什么?
【问题讨论】: