tags:

views:

179

answers:

3

I have an Ant task to compile jsp files with Jasper. The first step is generate the java files:

<java classname="org.apache.jasper.JspC" fork="no" failonerror="true">
    <classpath refid="my.class.path" />
    <arg value="-uriroot" />
    <arg value="${apps}" />
    <arg value="-d" />
    <arg value="${jsp}" />
    <arg value="-p" />
    <arg value="my.package.jsp" />
    <arg value="-webinc" />
    <arg value="${apps}/META-INF/gen-mappings.xml" />
    <arg value="-webapp" />
    <arg value="${apps}" />
</java>

When I launch this task I get:

BUILD FAILED
java.lang.ClassCastException: org.apache.tools.ant.AntClassLoader cannot be cast
 to java.net.URLClassLoader
        at org.apache.jasper.compiler.JspRuntimeContext.<init>(JspRuntimeContext
.java:113)
        at org.apache.jasper.JspC.initServletContext(JspC.java:1257)
        at org.apache.jasper.JspC.execute(JspC.java:1118)
        at org.apache.jasper.JspC.main(JspC.java:243)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        ...

How can I manage this problem? Thanks!

Claudio

A: 

Try

fork="true"

to launch a separate JVM, rather than inheriting the Ant JVM.

Jonathan Feinberg
Same problem even with this modification.
Claudio
+1  A: 

I don't think you're supposed to invoke JspC directly like that. Tomcat provides an Ant task specifically for this purposes, it may do the necessary classloader gymnastics for you

http://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html#Web%20Application%20Compilation

<jasper 
         validateXml="false" 
         uriroot="${webapp.path}" 
         webXmlFragment="${webapp.path}/WEB-INF/generated_web.xml" 
         outputDir="${webapp.path}/WEB-INF/src" />
skaffman
Same problem even with this modification.
Claudio
I would generally agree with using a jasper task, but there are several options available as command line switches, but lacking setters in JspC class. For OP's problem I would also recommend using `jasper` task.
Alexander Pogrebnyak
A: 

Found the problem. For a wrong dependency chain between the Ant tasks, the web application folder was empty, without any JSP. Corrected the chain and launched the jasper task with some JSP, all is ok. Thanks for help. Claudio

Claudio