File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Ant and Cactus - classpath issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Ant and Cactus - classpath issues" Watch "Ant and Cactus - classpath issues" New topic

Ant and Cactus - classpath issues

Juarez Alvares Barbosa Junior
Ranch Hand

Joined: Mar 18, 2002
Posts: 80
Hello there,
We are trying to run in-container tests using Ant and Cactus. As far as we know, the classpath is configured properly.
When we run our build file, the output is as follows:
<error message="TestSampleServlet" type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: TestSampleServlet
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
The directory in which our test classes are located is included in cactus classpath. The error above doesn't state if this classpath error is occurring in the client or the server.
The interesting point is that when we run our test using a web browser, everything works accordingly.
Please could anyone help ?
Thanks a lot !
Juarez Junior
Juarez Alvares Barbosa Junior
Ranch Hand

Joined: Mar 18, 2002
Posts: 80
Problem was fixed. Thanks,
Al Newman
Ranch Hand

Joined: Mar 30, 2003
Posts: 716

Al Newman
Ranch Hand

Joined: Mar 30, 2003
Posts: 716
To answer my own question, as I recall the classloader problem occured because the <cactus> element needed the class file of the cactus test on it's classpath, not merely inside the ear/war file but the actual compiled .class file.
Looking at my changes from 10 days ago it appears as if I added a <pathelement location="${env.target_dir}/build/tmp/cactus-test"/>
statement to the <classpath> subelement of the <cactus> element. This points to the top of the package directory heirarchy for the CactusTest.class file.
That is, if the java file is in
package foo.foo2;
and the actual class file is in ${env.target_dir}/build/tmp/cactus-test/foo/foo2/CactusTest.class
Then the classpath has to have the base dir ${env.target_dir}/build/tmp/cactus-test on it to work. One of the lovely little thorns of Cactus.
Hope this helps.
[ November 21, 2003: Message edited by: Alfred Neumann ]
I agree. Here's the link:
subject: Ant and Cactus - classpath issues
It's not a secret anymore!