Search code examples
tomcatclasscastexception

java.lang.ClassCastException while trying to use org.apache.catalina.loader.VirtualWebappLoader in Tomcat 7


I'm trying to build a development environment with Tomcat7 and several related webapp and Java projects.

As suggested (http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Virtual_webapp), I have configured the following context:

<Context path="/vcaui" docBase="/Users/alexey/EclipseWorkspaces/dooks/application/VCAUI/war" reloadable="true">                    
<Loader loaderClass="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/Users/alexey/EclipseWorkspaces/dooks/application/VCA/bin" />
<JarScanner scanAllDirectories="true" />
</Context>

I get the following error, trying to start Tomcat:

Aug 04, 2013 1:41:56 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Context/Loader} Setting property 'virtualClasspath' to '/Users/alexey/EclipseWorkspaces/dooks/application/VCA/bin' did not find a matching property.
Aug 04, 2013 1:41:56 PM org.apache.catalina.loader.WebappLoader startInternal
SEVERE: LifecycleException 
java.lang.ClassCastException: org.apache.catalina.loader.VirtualWebappLoader cannot be cast to  org.apache.catalina.loader.WebappClassLoader
at org.apache.catalina.loader.WebappLoader.createClassLoader(WebappLoader.java:731)
at org.apache.catalina.loader.WebappLoader.startInternal(WebappLoader.java:583)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5299)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)

Does anyone has a clue?


Solution

  • Try replacing the attribute loaderClass with className. I've used it in the past and took the example from this bit from the tomcat documentation

    (copying the example, in case the page disappears in the future)

    <Context path="/mywebapp" docBase="/Users/theuser/mywebapp/src/main/webapp" >
      <Resources className="org.apache.naming.resources.VirtualDirContext" 
                 extraResourcePaths="/WEB-INF/classes=/Users/theuser/mywebapp/target/classes" />
      <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
              virtualClasspath="/Users/theuser/mywebapp/target/classes; /Users/theuser/.m2/repository/log4j/log4j/1.2.15/log4j-1.2.15.jar" />
      <JarScanner scanAllDirectories="true" />
    </Context>