Apache Tomcat Maven Plugin
  1. Apache Tomcat Maven Plugin
  2. MTOMCAT-81

mvn tomcat:run does not work with spring tomcat classloader

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Not A Problem
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Ubuntu 10.10

      Description

      I have been trying for weeks to get the mvn tomcat:run work for my Spring based project. I use the spring-tomcat-weaver.jar for doing the class loading in Tomcat. When I run my project using mvn tomcat:run command it gives me a class not found. Below is a stack trace of what I get:

      SEVERE: LifecycleException
      java.lang.ClassNotFoundException: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
      at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
      at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
      at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:169)
      at org.apache.catalina.loader.WebappLoader.createClassLoader(WebappLoader.java:801)
      at org.apache.catalina.loader.WebappLoader.start(WebappLoader.java:661)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4504)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
      at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
      at org.apache.catalina.startup.Embedded.start(Embedded.java:825)
      at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)
      at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:316)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:451)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:188)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:134)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

        Activity

        Hide
        albert kam added a comment -

        Sorry, the configurations are:

        <contextFile>basedir/src/main/webapp/META-INF/context.xml</contextFile>
        <addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
        <classLoaderClass>org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader</classLoaderClass>
        <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>

        My context.xml file is:

        <?xml version="1.0" encoding="UTF-8"?>
        <Context path="/">
        <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
        </Context>

        I'm having the same situation with the original poster, running embedded tomcat with mvn:run

        Show
        albert kam added a comment - Sorry, the configurations are: <contextFile>basedir/src/main/webapp/META-INF/context.xml</contextFile> <addWarDependenciesInClassloader>true</addWarDependenciesInClassloader> <classLoaderClass>org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader</classLoaderClass> <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader> My context.xml file is: <?xml version="1.0" encoding="UTF-8"?> <Context path="/"> <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/> </Context> I'm having the same situation with the original poster, running embedded tomcat with mvn:run
        Hide
        albert kam added a comment -

        I'm using the plugin version of 2.3-SNAPSHOT and i still get this:

        SEVERE: LifecycleException
        java.lang.ClassNotFoundException: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:191)
        at org.apache.catalina.loader.WebappLoader.createClassLoader(WebappLoader.java:721)
        at org.apache.catalina.loader.WebappLoader.startInternal(WebappLoader.java:582)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5389)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        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:745)

        My configurations area:

        <contextFile>$

        Unknown macro: {basedir}

        /src/main/webapp/META-INF/context.xml</contextFile>
        <!-- <addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
        <classLoaderClass>org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader</classLoaderClass> -->
        <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>

        Show
        albert kam added a comment - I'm using the plugin version of 2.3-SNAPSHOT and i still get this: SEVERE: LifecycleException java.lang.ClassNotFoundException: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:191) at org.apache.catalina.loader.WebappLoader.createClassLoader(WebappLoader.java:721) at org.apache.catalina.loader.WebappLoader.startInternal(WebappLoader.java:582) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5389) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565) at java.util.concurrent.FutureTask.run(FutureTask.java:262) 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:745) My configurations area: <contextFile>$ Unknown macro: {basedir} /src/main/webapp/META-INF/context.xml</contextFile> <!-- <addWarDependenciesInClassloader>true</addWarDependenciesInClassloader> <classLoaderClass>org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader</classLoaderClass> --> <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
        Hide
        Olivier Lamy (*$^¨%`£) added a comment -

        use useSeparateTomcatClassloader=true

        Show
        Olivier Lamy (*$^¨%`£) added a comment - use useSeparateTomcatClassloader=true
        Hide
        Olivier Lamy (*$^¨%`£) added a comment -

        how is declared your dependency on spring-tomcat-weaver or spring-instrument-tomcat ?

        Show
        Olivier Lamy (*$^¨%`£) added a comment - how is declared your dependency on spring-tomcat-weaver or spring-instrument-tomcat ?
        Hide
        DZ added a comment -

        To reproduce this, add following lines in file META-INF/context.xml
        <?xml version="1.0" encoding="UTF-8"?>
        <Context path="/AnyWebApp">
        <Loader
        loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
        useSystemClassLoaderAsParent="false" />
        </Context>

        This is a typical config for spring + tomcat + maven.

        Show
        DZ added a comment - To reproduce this, add following lines in file META-INF/context.xml <?xml version="1.0" encoding="UTF-8"?> <Context path="/AnyWebApp"> <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" useSystemClassLoaderAsParent="false" /> </Context> This is a typical config for spring + tomcat + maven.
        Hide
        Olivier Lamy (*$^¨%`£) added a comment -

        need a sample project to test it.

        Show
        Olivier Lamy (*$^¨%`£) added a comment - need a sample project to test it.

          People

          • Assignee:
            Unassigned
            Reporter:
            Jothi Shankar Kumar
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development