Apache Ant – JUnitReport task – ClassNotFoundException: redirect
While using Ant to generate nice-looking junit reports the other day, I came across a problem which took a while to resolve. Here is the error message:
[junitreport] jar:file:/app/fao/rds/apache-ant-1.6.5/lib/ant-junit.jar !/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl; Line 37; Column 53; javax.xml.transform.TransformerException: java.lang.ClassNotFoundException: redirect [junitreport] jar:file:/app/fao/rds/apache-ant-1.6.5/lib/ant-junit.jar !/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl; Line 42; Column 57; javax.xml.transform.TransformerException: java.lang.ClassNotFoundException: redirect [junitreport] jar:file:/app/fao/rds/apache-ant-1.6.5/lib/ant-junit.jar !/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl; Line 47; Column 64; javax.xml.transform.TransformerException: java.lang.ClassNotFoundException: redirect ... etc.
It appears that this is caused by incompatible version of Xalan. If you’re working on a large project (like me), you may not have the luxury of being able to switch versions of libraries very easily.
Workarounds:
a) in the
b) You can ask junit-report to use a different stylesheet so that this problem doesn’t occur. The stylesheet in question is already distributed with ant.
- Make a directory to contain the unit test stylesheets
- Copy ${ant.home}/etc/junit-frames-xalan1.xsl to your-stylesheets-dir
- Rename junit-frames-xalan1.xsl to junit-frames.xsl
- In the
part of your ant task, add
styledir=”your-stylesheets-dir”- That’s it.
There’s also a bugzilla issue on this subject: http://issues.apache.org/bugzilla/show_bug.cgi?id=30200