Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.NoClassDefFoundError when trying to run JUnit tests from ANT
    primarykey
    data
    text
    <p>I'm having problems with a java.lang.NoClassDefFoundError when trying to run my JUnit tests from ANT using the runtestsreport task in thefollowing build.xml; I know the other tasks work, it's just the actual running of the tests that's the problem.</p> <p>I've tried lots of adjustments based on questions posted on here but I can't fix it; what I really need is a dev to pair with but they've all gone home for the day. </p> <p>Can anyone help?</p> <p>The build.xml file is </p> <p> </p> <pre><code>&lt;property name="build" location="C:\&lt;path on my machine&gt;\workspace\ESS\build"/&gt; &lt;property name="testsbuild" location="C:\&lt;path on my machine&gt;\workspace\ESS\build\esstestapp\tests"/&gt; &lt;property name="frameworkbuild" location="C:\&lt;path on my machine&gt;\workspace\ESS\build\esstestapp\framework"/&gt; &lt;property name="rawtestreports" location="C:\&lt;path on my machine&gt;\workspace\ESS\reports\raw"/&gt; &lt;property name="htmltestreports" location="C:\&lt;path on my machine&gt;\workspace\ESS\reports\html"/&gt; &lt;property name="reports" location="C:\&lt;path on my machine&gt;\workspace\ESS\reports"/&gt; &lt;property name="src" location="C:\&lt;path on my machine&gt;\workspace\ESS\src"/&gt; &lt;property name="testsrc" location="C:\&lt;path on my machine&gt;\workspace\ESS\src\esstestapp\tests"/&gt; &lt;property name="seleniumtools" location="C:\&lt;path on my machine&gt;\workspace\ESS\tools\junit-4.8.2"/&gt; &lt;property name="junittools" location="C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2"/&gt; &lt;target name="init"&gt; &lt;tstamp/&gt; &lt;mkdir dir="${build}"/&gt; &lt;mkdir dir="${rawtestreports}"/&gt; &lt;mkdir dir="${htmltestreports}"/&gt; &lt;/target&gt; &lt;path id="tools.classpath"&gt; &lt;fileset dir="${seleniumtools}" includes="**/*.jar"/&gt; &lt;fileset dir="${junittools}" includes="**/*.jar"/&gt; &lt;/path&gt; &lt;target name="compile" depends="init" description="compile the source" &gt; &lt;javac srcdir="${src}" destdir="${build}" classpathref="tools.classpath" includeantruntime="false"/&gt; &lt;/target&gt; &lt;target name="frameworkjar" depends="compile"&gt; &lt;jar destfile="${frameworkbuild}/jar/framework.jar" basedir="${frameworkbuild}" /&gt; &lt;/target&gt; &lt;target name="testsjar" depends="compile"&gt; &lt;jar destfile="${testsbuild}/jar/tests.jar" basedir="${testsbuild}" /&gt; &lt;/target&gt; &lt;path id="test.classpath"&gt; &lt;fileset dir="${seleniumtools}" includes="**/*.jar"/&gt; &lt;fileset dir="${junittools}" includes="**/*.jar"/&gt; &lt;fileset dir="${testsbuild}/jar" includes="**/*.jar"/&gt; &lt;fileset dir="${frameworkbuild}/jar" includes="**/*.jar"/&gt; &lt;/path&gt; &lt;target name="runtests" depends="compile, frameworkjar, testsjar" description="runs the tests" &gt; &lt;junit printsummary="yes" haltonfailure="no" showoutput="yes" fork="no"&gt; &lt;classpath refid="test.classpath" /&gt; &lt;batchtest fork="yes" todir="${rawtestreports}"&gt; &lt;formatter type="xml"/&gt; &lt;fileset dir="${testsrc}"&gt; &lt;include name="**/*.java"/&gt; &lt;/fileset&gt; &lt;/batchtest&gt; &lt;/junit&gt; &lt;/target&gt; &lt;target name="runtestsreport" depends="runtests"&gt; &lt;junitreport todir="${reports}"&gt; &lt;fileset dir="${rawtestreports}"&gt; &lt;include name="TEST-*.xml" /&gt; &lt;/fileset&gt; &lt;report format="frames" todir="${htmltestreports}" /&gt; &lt;/junitreport&gt; &lt;/target&gt; &lt;target name="clean" description="Clean up"&gt; &lt;delete dir="${build}"/&gt; &lt;delete dir="${reports}"/&gt; &lt;/target&gt; </code></pre> <p> </p> <p>I get this error (and this type of error for each test class) </p> <pre><code>Credentials (wrong name: esstestapp/tests/Credentials) java.lang.NoClassDefFoundError: Credentials (wrong name: esstestapp/tests/Credentials) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)... </code></pre> <p>I've ran ant in -verbose mode to check the classpath out but I can't see the problem (even though I know that it's staring me in the face)</p> <pre><code>[junit] Implicitly adding C:\Program Files\apache-ant-1.8.2\lib\ant-launcher .jar;C:\Program Files\apache-ant-1.8.2\lib\ant.jar;C:\Program Files\apache-ant-1 .8.2\lib\ant-junit.jar;C:\Program Files\apache-ant-1.8.2\lib\ant-junit4.jar to C LASSPATH [junit] Executing 'C:\Program Files\Java\jdk1.6.0_25\jre\bin\java.exe' with arguments: [junit] '-classpath' [junit] Executing 'C:\Program Files\Java\jdk1.6.0_25\jre\bin\java.exe' with arguments: [junit] '-classpath' [junit] 'C:\&lt;path on my machine&gt;\workspace\ESS\tools\junit-4.8.2\junit.jar;C:\User s\waltersj\workspace\ESS\tools\junit-4.8.2\junitsrc.jar;C:\&lt;path on my machine&gt;\worksp ace\ESS\tools\selenium-2.0rc2\apache-mime4j-0.6.jar;C:\&lt;path on my machine&gt;\workspace\ ESS\tools\selenium-2.0rc2\bsh-1.3.0.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\se lenium-2.0rc2\cglib-nodep-2.1_3.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\seleni um-2.0rc2\commons-codec-1.4.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2 .0rc2\commons-collections-3.2.1.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\seleni um-2.0rc2\commons-io-2.0.1.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2. 0rc2\commons-lang-2.4.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\ commons-logging-1.1.1.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\ cssparser-0.9.5.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\guava- r09.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\hamcrest-all-1.1.j ar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\htmlunit-2.8.jar;C:\Use rs\waltersj\workspace\ESS\tools\selenium-2.0rc2\htmlunit-core-js-2.8.jar;C:\User s\waltersj\workspace\ESS\tools\selenium-2.0rc2\httpclient-4.0.2.jar;C:\Users\wal tersj\workspace\ESS\tools\selenium-2.0rc2\httpcore-4.0.1.jar;C:\&lt;path on my machine&gt;\w orkspace\ESS\tools\selenium-2.0rc2\httpmime-4.0.1.jar;C:\&lt;path on my machine&gt;\workspac e\ESS\tools\selenium-2.0rc2\jcommander-1.13.jar;C:\&lt;path on my machine&gt;\workspace\ESS\ tools\selenium-2.0rc2\jna.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0 rc2\json-20080701.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\juni t-dep-4.8.1.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\nekohtml-1 .9.14.jar;C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\sac-1.3.jar;C:\U sers\waltersj\workspace\ESS\tools\selenium-2.0rc2\selenium-java-2.0rc2-srcs.jar; C:\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\selenium-java-2.0rc2.jar;C :\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\serializer-2.7.1.jar;C:\Use rs\waltersj\workspace\ESS\tools\selenium-2.0rc2\testng-6.0.1-nobsh-noguice.jar;C :\&lt;path on my machine&gt;\workspace\ESS\tools\selenium-2.0rc2\xalan-2.7.1.jar;C:\Users\wa ltersj\workspace\ESS\tools\selenium-2.0rc2\xercesImpl-2.9.1.jar;C:\Users\walters j\workspace\ESS\tools\selenium-2.0rc2\xml-apis-1.3.04.jar;C:\&lt;path on my machine&gt;\work space\ESS\build\esstestapp\tests\jar\tests.jar;C:\&lt;path on my machine&gt;\workspace\ESS\b uild\esstestapp\framework\jar\framework.jar;C:\&lt;path on my machine&gt;\workspace\ESS;C:\P rogram Files\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\apache-ant-1.8.2\lib\ ant-launcher.jar;C:\Program Files\apache-ant-1.8.2\lib\ant.jar;C:\Program Files\ apache-ant-1.8.2\lib\ant-junit.jar;C:\Program Files\apache-ant-1.8.2\lib\ant-jun it4.jar' </code></pre> <p>Any eyes over this to help me get the tests running would be greatly appreciated.</p> <p>Thanks</p> <p>James</p> <p><strong>Update</strong></p> <p>I observe that if I edit tests.classpath to remove the following 2 lines then the error I see switches to a ClassNotFound which makes sense as it has no references to the .jar files that contain the classes.</p> <pre><code>&lt;fileset dir="${testsbuild}/jar" includes="**/*.jar"/&gt; &lt;fileset dir="${frameworkbuild}/jar" includes="**/*.jar"/&gt; </code></pre> <p>With the above 2 lines present in the tests.classpath is happily finds them but with the wrong name and it's that error I don't know how to fix.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload