14

I've written a couple of servlets on my local machine using eclipse. I've tested them on my local machine and everything works perfectly fine.

I then exported my project as a .war file and put it under the webapps directory of my tomcat in another machine to which I only have ssh access to. I restarted my tomcat server and after looking at the log files I see that it's throwing 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(AbstractSAXParser.java:604)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1759)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2915)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)
at org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1875)
at org.apache.catalina.startup.ContextConfig.getDefaultWebXmlFragment(ContextConfig.java:1472)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1250)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
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:5173)
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.deployWAR(HostConfig.java:968)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1646)
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:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)

No idea what this means?

Roozbeh15
  • 4,047
  • 6
  • 27
  • 30
  • This thread could help you. [link](http://stackoverflow.com/questions/6110660/porting-tomcat-6-to-7-problem-with-filter) – Subhrajyoti Majumder Nov 02 '12 at 04:44
  • I've seen that thread, but I'm no using maven, nor editing the web.xml. To my understanding I shouldn't need web.xml in servlet3.0 because they're replaced by annotations. If that is the case why am I getting this error ? – Roozbeh15 Nov 02 '12 at 04:45
  • Check if you are running the same version in both the places. Usually it should not matter. So provide the version of your and the remote machine. Please post your web.xml snippet as well. You can see Xerces all over the stack trace. There is some servlet in web.xml that could not be loaded. Stop your remote tomcat server. Cleanup your temp and work directories. Tomcat explodes the war files once it starts. Can you confirm there are no files in the directory with the same name. – randominstanceOfLivingThing Nov 02 '12 at 06:12

2 Answers2

21

I found the solution here.

I was right as in you don't need to have the web.xml anymore. You can simply use annotations to define paths for your servlet. But the problem was that I was including catalina.jar in my lib which was causing issues. Removing catalina.jar fixed things up!

Winter
  • 3,894
  • 7
  • 24
  • 56
Roozbeh15
  • 4,047
  • 6
  • 27
  • 30
  • 1
    Read this carefully: http://stackoverflow.com/questions/4076601/how-do-i-import-the-javax-servlet-api-in-my-eclipse-project/4076706#4076706 If you placed `catalina.jar` in your `/WEB-INF/lib` for some unobvious reason (for which I can't imagine any reasonable starter's mistake as cause), then you might have done some other things wrong as well. – BalusC Nov 02 '12 at 17:54
  • I had read online that I should've put all my jars under /WEB-INF/lib. Even though, I had added all jars to my project, I couldn't see them in that directory and thought it might cause problems later. So, I basically copied and pasted all the jars into /WEB-INF/lib manually, which I shouldn't have. But thanks that link, helped. – Roozbeh15 Nov 02 '12 at 18:36
  • 2
    It undoubtedly meant the webapp-specific JARs, not the servletcontainer-specific JARs. – BalusC Nov 02 '12 at 19:03
  • 2
    This could happen as well that a maven dependency adds some of the Tomcat or other servlet container's JARs into your project (without your knowledge). That was the case for me. – Adam May 15 '13 at 21:05
3

I met this problem after I use maven into my project. As Adam said, I removed all tomcat libs in the maven dependencies and then the problem fixed.

Andong Zhan
  • 12,608
  • 4
  • 24
  • 24