【问题标题】:Ant Error when invoking it inside Eclipse在 Eclipse 中调用它时出现 Ant 错误
【发布时间】: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>

我错过了什么?

【问题讨论】:

    标签: java ant build


    【解决方案1】:

    确保 ant 库位于您的类路径中。
    看来,您的类路径中缺少 ant-launcher-VERSION.jar(其中 Version 是您正在使用的 ant 版本)。

    【讨论】:

    • 谢谢。很多例子只说添加 ant.jar 而不是 ant-launcher.jar。
    猜你喜欢
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-01
    • 2011-12-12
    • 2019-05-10
    • 1970-01-01
    • 2013-09-07
    相关资源
    最近更新 更多