I’m trying to get Ant to run my JUnit tests now but I keep getting
Testsuite: net.anthonychaves.test.geoip.locator.LocatorHelpersTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 secCaused an ERROR
net.anthonychaves.test.geoip.locator.LocatorHelpersTest
java.lang.ClassNotFoundException: net.anthonychaves.test.geoip.locator.LocatorHelpersTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
I’m not sure how that can happen because the JUnit section of build.xml file looks like this:
[junit printsummary="yes" fork="yes" dir="${basedir}/build/classes/"]
[classpath]
[pathelement path="/home/anthony/jboss-4.0.4.GA/client/jboss-j2ee.jar"/]
[pathelement path="/home/anthony/eclipse/plugins/org.junit_3.8.1/junit.jar"/]
[pathelement path="/m2/ark/code/mysql-connector-java-3.1.12/mysql-connector-java-3.1.12-bin.jar"/]
[fileset dir="${basedir}/build/classes/"]
[include name="**/*Test.class"/]
[/fileset]
[/classpath]
[formatter type="plain"/]
[batchtest todir="/home/anthony/junit/reports" ]
[fileset dir="${basedir}/test/"]
[include name="**/*Test.java"/]
[/fileset]
[/batchtest]
[/junit]
I’m not sure why it can’t find the class at this point and I don’t have enough time to debug it tonight. It’s finding the class name well enough to try to run the test, but it’s not finding the class to do it. I guess I’ll have something to think about on my train ride tomorrow. Any suggestions would be helpful!





4 comments ↓
I have the same errors.
if you have any idea.
tell me .
thx!
I’m going to write up my solution more clearly and post it here in the next day or so. I’ve got a working build.xml file but unfortunately I put it in the wrong directory on my server and I can’t move it until tonight when I get home. I’ll let you know when I move it so you can at least look at the working file until I write up the process to get there.
I’m just eyeballing this, but I think you just need to set up your classpath differently. Normally to specify a directory in a path structure, you’d want to do something like:
lt;classpathgt;
lt;pathelement path=”/home/anthony/jboss-4.0.4.GA/client/jboss-j2ee.jar”/gt;
lt;pathelement path=”/home/anthony/eclipse/plugins/org.junit_3.8.1/junit.jar”/gt;
lt;pathelement path=”/m2/ark/code/mysql-connector-java-3.1.12/mysql-connector-java-3.1.12-bin.jar”/gt;
lt;pathelement location=”${basedir}/build/classes”/gt;
lt;/classpathgt;
I think the key is that it isn’t normal to specify classes in your classpath - generally you only specify jars and directories. The Ant docs are pretty good and I think they are pretty clear on this, see: http://ant.apache.org/manual/using.html#path
Sorry:
<classpath>
<pathelement path=”/home/anthony/jboss-4.0.4.GA/client/jboss-j2ee.jar”/>
<pathelement path=”/home/anthony/eclipse/plugins/org.junit_3.8.1/junit.jar”/>
<pathelement path=”/m2/ark/code/mysql-connector-java-3.1.12/mysql-connector-java-3.1.12-bin.jar”/>
<pathelement location=”${basedir}/build/classes”/>
</classpath>
Leave a Comment