English 中文(简体)
Cobertura ant script is missing Log4J classes
原标题:

I tried to get Cobertura running inside my ant script, but I m stuck right at the beginning. When I try to insert the cobertura taskdef I m missing the Log4J libraries.

Ant properties & classpath

<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" />

My ant target

<!-- ================================= 
      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>

I think I did everything like it is described in the Cobertura documentation but I get this

Ant build error

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

Inside the ${cobertura.dir} there is the lib directory with all files. I unzipped it from the cobertura distribution ZIP directly into that directory.

Am I missing a step? Something wrong with my configuration so far?

最佳回答

I also encountered this problem today and solved it by specifying the location of all the required libraries as part of the class path provided to my taskDef task.

<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" />
问题回答

Go to your ant/lib dir and make sure there is NO file cobertura.jar there. If it s there - remove it and try again.

Change this

<include name="lib/**/*.jar" />

to

<include name="*.jar" />

Hope this helps!

I just upgraded to the latest cobertura and mine works fine. Is it possible that something else is on the CLASSPATH with a different version of log4j so it is picking up wrong one?

Make sure that classpath used in taskdef and cobertura-instrument are the same. This helped me with the same issue.

I too faced this problem, I just added all jars given with cobertura in the classpath to resolve this issue





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签