创建一个Ant目标来运行jar中的java类

时间:2012-10-22 16:39:25

标签: java ant

我正在研究一个涉及包含许多不同源文件的大型jar的问题。其中一个源文件是测试类,我想从另一个项目运行该测试类。 这个测试类有一个主类,应该使用从ant传递给它的参数。 虽然问题似乎是阶级路径。我一直收到这个错误:

Exception in thread "main" java.lang.NoClassDefFoundError: junit.framework.TestCase

这是我被剥夺的目标。

    <target name="lookup-excute" description="Runs a Look up on all event files in the input folder.">
    <java classname="com.testing.LookupTest" failonerror="true" fork="yes">
        <arg value="${events.location}"/>
        <classpath>
            <pathelement path="..${file.separator}jars${file.separator}testing.jar"/>
        </classpath>
    </java>
</target>

1 个答案:

答案 0 :(得分:0)

一般情况下:当你有一个ClassNotFound时,你应该在你的一个jar文件中找到该类。你只需打开一个jar(使用与zip文件相同的工具)并尝试浏览junit / framework并找到TestCase.class jar。

如果您没有在任何广告罐中看到该课程,请在互联网(或jarfinder)上搜索课程名称。然后你知道你需要一个额外的jar,就像这个例子中的junit。如果你知道你想要“junit”,你可以从主页上下载,或者在大多数情况下从maven轻松下载:maven search

我不知道你是否可以直接运行junit测试。通常你会使用junit task

相关问题