java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addServlet
Asked Answered
R

7

20

I am migrating my web application from Jboss 4.2 to tomcat 7 .
After using the tomcat 7 i am facing the following exception.

java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addServlet
    at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:855)
    at org.apache.tomcat.util.digester.SetNextRule.end(SetNextRule.java:201)
    at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1051)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)
    at org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1883)
    at org.apache.catalina.startup.ContextConfig.getDefaultWebXmlFragment(ContextConfig.java:1469)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1246)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5269)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

I have tried to remove the catalina.jar (according to the solution given for the same exception)from the lib to solve the issue but it didn't worked.

I am not getting any way to solve this issue can anyone please help on this issue.

Rufena answered 5/7, 2013 at 10:56 Comment(1)
can you post the code for your web.xml file?Issacissachar
U
32

In your pom.xml if you have included dependencies like tomcat-catalina, put the scope as provided

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-catalina</artifactId>
  <version>7.0.47</version>
  <scope>provided</scope>
</dependency>

The container ( here tomcat ) itself provides some dependencies ( like tomcat-catalina jar ) when you deploy your app. So you don't need to include them in your application. But the jars are needed for compilation. This is achieved by setting the scope as 'provided'

Ulises answered 4/11, 2013 at 17:33 Comment(0)
C
13

I believe, this error is about the deployment assembly. You do not need the catalina.jar in the deployment assembly.

Confound answered 10/9, 2013 at 16:19 Comment(2)
I was breaking my head with this for a couple of days now. Thank you very much for the answer.Collarbone
Yes, it works after removing catalina.jar in tomcat 7.Phillip
A
1

For the ones like me facing this issue with Spring Boot, adding this dependency solved it :

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
Almeida answered 21/8, 2017 at 9:21 Comment(0)
G
0

add <scope>provided</scope> into pom.xml :

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-catalina</artifactId>
  <version>7.0.27</version>
  <scope>provided</scope>
</dependency>
Grazing answered 11/12, 2017 at 17:31 Comment(0)
R
0

For me, this error was being produced because my derived implementation of ServletContextListener had a CONCTRUCTOR PARAMETER. Apparently Spring/Java/Whatever can't load it up if you have ctor params, even though the params have values in the Application Context.

Hope this helps others.

Rehabilitation answered 12/11, 2018 at 11:32 Comment(0)
Q
0

I had this problem today, and it was because my executable spring boot jar had /BOOT-INF/lib/tomcat-embed-core-9.0.62.jar and my deployed WAR also had ../ROOT/WEB-INF/lib/tomcat-embed-core-9.0.62.jar. The jars were identical, but the tomcat webapp classloader creates a ProtectionDomain for the jars provided from BOOT-INF, and my deployed WAR was attempting to load the class from ROOT/WEB-INF/lib.

The fix is to make sure my deployed WAR uses jars from BOOT-INF ... I just have to figure out how to make that happen.

Quillon answered 26/7, 2022 at 22:15 Comment(0)
W
-3

There is another solution when you do need the catalina.jar, add

<Loader delegate="true"/> 

to

<Context />

element in %TOMCAT_HOME%/conf/context.xml

Worser answered 3/6, 2016 at 2:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.