aspose file tools*
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
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Ant and Cactus - classpath issues" Watch "Ant and Cactus - classpath issues" New topic
Author

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 java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
</error>
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.
http://localhost:8080/test/ServletTestRunner?suite=TestSampleServlet
Please could anyone help ?
Thanks a lot !
Juarez Junior
SCPJ2/SCWCD/SCBCD
Juarez Alvares Barbosa Junior
Ranch Hand

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

Joined: Mar 30, 2003
Posts: 716
How?


SCJP1.4, SCWCD
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ant and Cactus - classpath issues