我有一个用 Jasper 编译 jsp 文件的 Ant 任务。第一步是生成 java 文件:
<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>
当我启动这个任务时,我得到:
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)
...
我该如何解决这个问题? 谢谢!
克劳迪奥
最佳答案
我认为您不应该像那样直接调用JspC
。 Tomcat 专门为此提供了一个 Ant 任务,它可以为您完成必要的类加载器操作
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" />
关于java - AntClassLoader 无法转换为 URLClassLoader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1749500/