java - Cobertura ant 脚本缺少 Log4J 类

标签 java ant build-process code-coverage cobertura

我试图让 Cobertura 在我的 ant 脚本中运行,但我一开始就卡住了。当我尝试插入 cobertura taskdef 时,我缺少 Log4J 库。

Ant 属性和类路径

<property name="cobertura.dir" location="/full/path/to/cobertura-1.9.3" />
<path id="cobertura.classpath">
    <fileset dir="${cobertura.dir}">
        <include name="cobertura.jar" />
        <include name="lib/**/*.jar" />
    </fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />

我的 Ant 目标

<!-- ================================= 
      target: cobertura              
     ================================= -->
<target name="cobertura" depends="clean, init" description="Generates cobertura coverage reports">
    <cobertura-instrument todir="${dir.build.instrumented}">
        <fileset dir="${dir.build}">
            <include name="**/*.class" />
        </fileset>
    </cobertura-instrument>
</target>

我想我所做的一切都与 Cobertura documentation 中描述的一样但我明白了

Ant 构建错误

BUILD FAILED
build.xml:95: java.lang.NoClassDefFoundError: org/apache/log4j/Logger

${cobertura.dir} 中有包含所有文件的 lib 目录。我将它从 cobertura 分发 ZIP 中直接解压缩到该目录中。

我错过了一步吗?到目前为止我的配置有问题吗?

最佳答案

我今天也遇到了这个问题,并通过将所有必需库的位置指定为提供给我的 taskDef 任务的类路径的一部分来解决它。

<path id="cobertura.class.path">
    <pathelement location="${common.dir}/../tools/cobertura/cobertura.jar" />
    <pathelement location="${common.dir}/../tools/cobertura/lib/asm-3.0.jar" />
    <pathelement location="${common.dir}/../tools/cobertura/lib/asm-tree-3.0.jar" />
    <pathelement location="${common.dir}/../tools/cobertura/lib/log4j-1.2.9.jar" />
    <pathelement location="${common.dir}/../tools/cobertura/lib/jakarta-oro-2.0.8.jar" />
</path>

<taskdef classpathref="cobertura.class.path" resource="tasks.properties" />

关于java - Cobertura ant 脚本缺少 Log4J 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1774889/

相关文章:

c# - 从批处理文件构建 .net 解决方案

java - Vaadin 8.1.7 带有 ComponentRenderer 的网格

java - java中如何查找字符串

ant - 如何制作自定义ant任务?

java - 维护 GWT Web 应用程序的构建版本号

javascript - 如何将字符串发送到 Gulp 任务中?

java - AWS IoT SDK - 构建 AWSIotData 和 AWSIotClient 时出现异常

java - 为什么 QTP 对象类会从 JavaWindow 更改为 Window

java - Ivy:配置不存在

c# - 如何获取构建过程模板中的参数值