Hi,
There is a ClassCastException when we run the JspC class with the proper
arguments.
I have given the detailed exception at the end of this mail,
// In org.apache.jasper.JspC class code
private void initServletContext()
{
try
{
context = new JspCServletContext(new PrintWriter(System.out), new
URL("file:" + uriRoot.replace('\\', '/') + '/'));
tldLocationsCache = new TldLocationsCache(context, true);
}
catch(MalformedURLException me)
{
System.out.println("**" + me);
}
rctxt = new JspRuntimeContext(context, this);
jspConfig = new JspConfig(context);
tagPluginManager = new TagPluginManager(context);
}
In this method it creates the object of jspRunTimeContext
rctxt = new JspRuntimeContext(context, this);
// end JspC class code
// In org.apache.jasper.compiler.JspRuntimeContext class
In constructor of this class,
public JspRuntimeContext(ServletContext context, Options options) {
jsps = Collections.synchronizedMap(new HashMap());
thread = null;
threadDone = false;
threadName = "JspRuntimeContext";
System.setErr(new SystemLogHandler(System.err));
this.context = context;
this.options = options;
// The below line causing the exception to be thrown
parentClassLoader =
(URLClassLoader)Thread.currentThread().getContextClassLoader();
if(parentClassLoader == null)
parentClassLoader = (URLClassLoader)getClass().getClassLoader();
if(log.isDebugEnabled())
if(parentClassLoader != null)
log.debug(Localizer.getMessage("jsp.message.parent_class_loader_is",
parentClassLoader.toString()));
else
log.debug(Localizer.getMessage("jsp.message.parent_class_loader_is", "<none>"));
initClassPath();
if(context instanceof JspCServletContext)
return;
if(System.getSecurityManager() != null)
...
..}
// Here it is expecting the current thread class loader to be of type
URLClassLoader,
which is not,it is set with the AntClassLoader2..
Hence throwing the exception
parentClassLoader =
(URLClassLoader)Thread.currentThread().getContextClassLoader();
/// end of org.apache.jasper.compiler.JspRuntimeContext class
The reason is the current thread class loader has set in JspC after
JspRuntimeContext() object
creation call,
setting of current thread class loader to URLClassLoader is done in the below
given method in JspC class
private void initClassLoader(JspCompilationContext clctxt) method
// Begin JspC class
Thread.currentThread().setContextClassLoader(loader);
// end JspC class
The class loader, URLClassLoader is set to the current thread after the
exception is thrown from
org.apache.jasper.compiler.JspRuntimeContext, if it set before ,then it will
definitely work.
--- total flow.
from JspC class,
methods flow
Main() -- execute()--- initServletContext();
initServletContext() In this method creating the below object by calling the
only one constructor of
org.apache.jasper.compiler.JspRuntimeContext(context, option)
------
in org.apache.jasper.compiler.JspRuntimeContext
org.apache.jasper.compiler.JspRuntimeContext
taking the current thread class loader and expecting to be as URLClassloader,
exception thrown
-----------
in JspC
after this flow there is code to set the currentCLassLoader to URLClassLoader,
in initClassLoader(JspCompilationContext clctxt) method
this should be set before the creation of JspRuntimeContext object to avoid
this exception.
---
It would be great if we have precompilation feature.
I don't know if there is any other alternatives available for this,
I think we could do this. Please let me know if this is
considered already and have counter this problem.
---
The detailed exception is ...........
The line numbers may not correct since i put some System.out.println()..
The code thrrowing the exception is
JspRuntimeContext costructor
parentClassLoader =
(URLClassLoader)Thread.currentThread().getContextClassLoader();
////////////////
[java] java.lang.ClassCastException
[java] at
org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:172)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:705)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:177)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:83)
[java] at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:341)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:673)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:188)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
[java] Caused by: java.lang.ClassCastException
[java] at
org.apache.jasper.compiler.JspRuntimeContext.<init>(JspRuntimeContext.java:95)
[java] at org.apache.jasper.JspC.initServletContext(JspC.java:1005)
[java] at org.apache.jasper.JspC.execute(JspC.java:870)
[java] at org.apache.jasper.JspC.main(JspC.java:196)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at
org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:193)
[java] at
org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:130)
[java] ... 13 more
[java] --- Nested Exception ---
[java] java.lang.ClassCastException
[java] at
org.apache.jasper.compiler.JspRuntimeContext.<init>(JspRuntimeContext.java:95)
[java] at org.apache.jasper.JspC.initServletContext(JspC.java:1005)
[java] at org.apache.jasper.JspC.execute(JspC.java:870)
[java] at org.apache.jasper.JspC.main(JspC.java:196)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at
org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:193)
[java] at
org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:130)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:705)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:177)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:83)
[java] at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:341)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:673)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:188)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Regards,
Jagga
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com