2

I'm currently trying to deal with the following error caused by a junit task:

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

My target is currently configured as this:

<target name="test" depends="include">
    <mkdir dir="${reports}" />

    <mkdir dir="${reports}/${build}" />
    <!--<javac srcdir="src" includes="**/test/*.java" destdir="${reports}/${build}" />-->

    <junit printsummary="on" haltonfailure="on" includeantruntime="on">
        <classpath>
            <pathelement location="${reports}/${build}" />
            <pathelement location="/usr/share/java/hamcrest-core.jar" />
            <!--<pathelement location="/usr/share/java/junit.jar" />-->
        </classpath>

        <formatter type="plain"/>

        <batchtest todir="${reports}">
            <formatter type="brief"/>
            <fileset dir="src">
                <include name="**/test/*.java" />
            </fileset>
        </batchtest>
    </junit>

    <delete dir="${reports}/${build}" quiet="true" />
</target>

I have already tried to use the system's junit jar, currently I'm including ant runtime which already includes a junit jar from somewhere, and I also tried having or not having that hamcrest path on the junit classpath.

I also tried compiling the tests before (the commented javac line). I am not a Java programmer, so to me this classpath stuff is a complete mess.

Grepping /usr/share/java/hamcrest-core.jar shows there is something called SelfDescribing inside it. There are also other files called hamcrest-library.jar, hamcrest-generator.jar and hamcrest-integration.jar, but none of them neither any combination works.

ranieri
  • 2,030
  • 2
  • 21
  • 39
  • What happens if you add `-lib /usr/share/java/hamcrest-core.jar` to your Ant command line? – Chad Nouis Oct 09 '15 at 16:12
  • Possible duplicate of [Ant + JUnit: NoClassDefFoundError](http://stackoverflow.com/questions/1171264/ant-junit-noclassdeffounderror) – Stefan Birkner Oct 09 '15 at 16:42
  • @ChadNouis nothing changes, still hamcrest not found – ranieri Oct 09 '15 at 17:30
  • I added a Getting started section about Ant to the JUnit Wiki that works: https://github.com/junit-team/junit/wiki/Getting-started-%E2%80%93-Ant It has different attributes for the `junit` task. – Stefan Birkner Oct 09 '15 at 21:09

0 Answers0