如何在Ant Junit任务中显示类路径构建

use*_*724 1 ant

已经工作了几个月的Ant junit任务突然失败,对于以前找到的类,NoClassDefFoundError.有没有办法显示在junit任务中构建的类路径?

<target name="basic-junit-test" description="Run a single JUnit test. ">

    <junit printsummary="yes" fork="no" haltonfailure="yes">
        <classpath>
            <pathelement location="target/WEB-INF/lib/log4j-1.2.16.jar"/> 
            .
            . many other pathelements
            .
        </classpath>
        <test name="com.mycompany.command.TestUNLOCKACCOUNTCommand" outfile="${report.dir}/junit_test_results" />
    </junit>
</target>
Run Code Online (Sandbox Code Playgroud)

Mar*_*nor 5

我非常喜欢在我的构建顶部声明我的Ant路径并在各种任务中使用类路径引用.

to pathconvert task可用于将类路径内容打印为属性:

<path id="test.path">
    <pathelement location="target/WEB-INF/lib/log4j-1.2.16.jar"/> 
    .
    . many other pathelements
    .
</path>

<target name="echo-path" description="Echo test path">
    <pathconvert targetos="unix" property="test.path.unix" refid="test.path">
    <echo message="Test path: ${test.path.unix}"/>
</target>

<target name="basic-junit-test" depends="echo-path" description="Run a single JUnit test. ">

    <junit printsummary="yes" fork="no" haltonfailure="yes">
        <classpath>
            <path refid="test.path"/>
        </classpath>
        <test name="com.mycompany.command.TestUNLOCKACCOUNTCommand" outfile="${report.dir}/junit_test_results" />
    </junit>
</target>
Run Code Online (Sandbox Code Playgroud)

更新

刚发生在我身上:一个更简单的解决方案可能是在调试模式下运行Ant.

  • 要在调试模式下在Eclipse中运行Ant,请在Ant编辑器中使用=> AntFile 上下文菜单| 运行为| 2 Ant Build ... | 主要标签| Arguments => -debug然后运行 (2认同)