java.lang.ClassNotFoundException: HttpServletRequest
Asked Answered
M

16

29

I just got tomcat 7.0.27. I have kept the time to start tomcat 45sec. Also it was running fine with older version on tomcat. but running it I get the following error :

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/VotingApp]]
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
    at java.util.concurrent.FutureTask.get(FutureTask.java:83)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:782)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/VotingApp]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 7 more
Caused by: java.lang.NoClassDefFoundError: HttpServletRequest
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
    at java.lang.Class.getDeclaredMethods(Class.java:1791)
    at org.apache.catalina.startup.WebAnnotationSet.getDeclaredMethods(WebAnnotationSet.java:470)
    at org.apache.catalina.startup.WebAnnotationSet.loadMethodsAnnotation(WebAnnotationSet.java:275)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:137)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:66)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:381)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:858)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
    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:5161)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more
Caused by: java.lang.ClassNotFoundException: HttpServletRequest
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    ... 21 more
May 11, 2012 10:09:21 AM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
    at java.util.concurrent.FutureTask.get(FutureTask.java:83)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:675)
    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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1136)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:782)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more
May 11, 2012 10:09:21 AM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:675)
    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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1136)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 11 more
May 11, 2012 10:09:21 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 561 ms

How do I resolve the error. I have looked into some similar posts but did not find it useful.

Milan answered 11/5, 2012 at 17:46 Comment(2)
I see that the cause might be Caused by: java.lang.NoClassDefFoundError: HttpServletRequestMilan
Resolved it. Did not check if I had the appropriate servlet jarMilan
M
46

Your web app has servlet container specific libraries like servlet-api.jar file in its /WEB-INF/lib. This is not right. Remove them all. The /WEB-INF/lib should contain only the libraries specific to the Web app, not to the servlet container. The servlet container (like Tomcat) is the one who should already provide the servlet container specific libraries. If you supply libraries from an arbitrary servlet container of a different make/version, you'll run into this kind of problems, as your web app wouldn't be able to run on a servlet container of a different make/version than those libraries originated from.

This is a pretty common starter's mistake when they encounter compile-time errors, as they haven't set up their IDE project right. See also How do I import the javax.servlet API in my Eclipse project?

Matchmaker answered 11/5, 2012 at 17:55 Comment(9)
I've been spending a few hours chasing this one down without success. I have looked through every single jar in WEB-IN/lib and not found any containing 'HttpServletRequest'. Is there any other way of figuring out which is the offending jar?Flea
Wouldn't just mark the servlet-api as 'provided' solve this issue?Berneta
This help me! ThanksGrindelia
But maven put jars in WEB-INF/lib. What should I do then - with maven?Lvov
@parsecer: just mark it as <scope>provided</scope> to tell Maven that it's already provided by the target runtime. See also the "See also" link in end of the above answer.Matchmaker
@BalusC, no. I've always had javax.servlet depedency in pom.xml in Maven - without limiting its scope. It just needed to be the same version as javax.servlet in Tomcat/lib. I downloaded jar of the same version and put it in tomcat/lib and now it works.Lvov
@parsecer: This is not the correct approach :) You will in long term run into "weird" problems of all sorts making you to pull out hairs.Matchmaker
@Matchmaker Thanks, I'll keep it in mind. So the whole point is to let Tomcat use the version of javax.servlet that it needs, while providing whatever version your code needs in pom.xml/direct IDE jar importing? And the provided scope would prevent from Tomcat seeing that source code's version that it might feel incompatible with?Lvov
@parsecer: No. Tomcat already provides it out its own box. Let it use that in all peace. You can see the existing JAR already sitting in its /lib folder. With the provided-scoped declaration in pom.xml you're basically telling your tooling to be able to compile against that.Matchmaker
P
21

Caused by: java.lang.NoClassDefFoundError: HttpServletRequest

The above problem can be because the javax library is not found.

I solved the same problem with:
Right click on the project in Eclipse → PropertiesJava Build PathLibrariesAdd library...Server RuntimeApache Tomcat

Platt answered 29/5, 2013 at 12:51 Comment(0)
A
4

add following in your pom.xml .it works for me.

     <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
     </dependency>
Avogadro answered 2/11, 2015 at 7:36 Comment(1)
This worked partially for me. I also had to add commons-logging.jar to the WEB-INF/lib folder, (not sure if a maven install is also required at the end).Archle
P
3

I did not have a servlet-api.jar in the application's WEB-INF/lib directory (or any other jar there). The problem was that in WEB-INF/web.xml I had this...

    ...
    <servlet>
      <servlet-name>MyServlet</servlet-name>
      <servlet-class>com.bizooka.net.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>MyServlet</servlet-name>
      <url-pattern>/MyServlet</url-pattern>
    </servlet-mapping>
    ...

...according to a tutorial. Removing that still allowed the servlet to function, and did not get the error.

Publicity answered 24/5, 2015 at 20:13 Comment(1)
what if I don't have web.xml file?Salutation
V
0

I do have same problem when i was trying out with first Spring MVC webapp . What i had done was downloaded the jar files given from the link(Download spring framework). Among the jars on the zip extracted folder,the jar files I was expected to use were

  • org.springframework.asm-3.0.1.RELEASE-A.jar

  • org.springframework.beans-3.0.1.RELEASE-A.jar

  • org.springframework.context-3.0.1.RELEASE-A.jar

  • org.springframework.core-3.0.1.RELEASE-A.jar

  • org.springframework.expression-3.0.1.RELEASE-A.jar

  • org.springframework.web.servlet-3.0.1.RELEASE-A.jar

  • org.springframework.web-3.0.1.RELEASE-A.jar

But as I get the Error, looking out for solution, I figured out that I also need the following jar too.

  • commons-logging-1.0.4.jar

  • jstl-1.2.jar

Then I searched and downloaded the two jar files separately and include them in /WEB-INF/lib folder. And finally I was able to get my webapp running using the Tomcat server. :)

Vault answered 28/3, 2016 at 4:31 Comment(0)
E
0

you should add servler-api.jar file in WEB-INF/lib folder

Eggplant answered 29/6, 2016 at 7:30 Comment(0)
S
0

I have just deleted the declaration of the servlet in the web.xml file and it works for me.

Good luck

Sieber answered 28/8, 2016 at 21:27 Comment(0)
A
0

This one is for all the Maven users out there, using their dependencies for the classpath and not copying them into /WEB-INF/lib: just add this (which copies the dependency libraries) before </plugin>

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <phase>process-sources</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>WebContent/WEB-INF/lib</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
Araceli answered 2/4, 2017 at 10:38 Comment(0)
S
0

I had the same problem, and the cause was the missing of commons-logging-1.2.jar

I add it to the lib folder, then my Apache Tomcat 7 server executed without problems.

Shrunk answered 15/6, 2017 at 11:50 Comment(0)
T
0

The same error i got

Caused by: org.apache.catalina.LifecycleException: A child container failed during start

I deleted the project from eclipse work space , deleted .settings folder of project and re imported to the eclipse. Did the trick for me.

Terrel answered 24/3, 2018 at 15:25 Comment(0)
E
0

I had this issue too, and all I did to get rid of it was to delete the existing Server (in my case Tomcat) configurations from project and eclipse workspace.

This issue in my case occurred when I played around with my Maven settings and finally screwed them too. But eventually I fixed my Maven issues to realize the tomcat server wont start and failed to load the application context(s) of various apps involved in my project. That's when I decided to drop the existing server configurations.

I then added the Apache Server once again all over afresh. Then followed with my project specific setting/additions. And it finally worked like a charm.

Elmira answered 9/12, 2020 at 6:46 Comment(0)
D
-1

So the problem is connected with the metadata errors of elcipse. Go to the metadata folder where this configuration is saved. For me one of the erorrs was that:

SEVERE: Error starting static Resources java.lang.IllegalArgumentException: Document base C:\Users\Cannibal\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\FoodQuantityService does not exist or is not a readable directory

So go there is in the workspace of your eclipse it is different for all and delete all its content . My services was named FoodQuantityService so I deleted all files in org.eclipse.wst.server.core but before that delete your server configuration from Eclipse

Delete current server configuration

Then create new configuration File->New->Other->Server select Tomcat and then projects which you want to be published. Start the server and everything will be ok.

Dioptric answered 2/6, 2013 at 17:46 Comment(1)
This worked for me out of all the ones I found in this thread.Corunna
R
-1

If any project that you were using and now closed in workspace might lead to this issue, try deleting context from server folder inside eclipse or open the projects.

Requisite answered 7/4, 2014 at 7:19 Comment(0)
I
-1

I came across the same problem when using eclipse-jee. I found the reason of this problem is that I had two or more duplicate @WebServlet("/yourServlet") definition in my web-app,so solution is to eliminate duplicates

Impeccant answered 19/4, 2014 at 13:53 Comment(0)
E
-1

1 Right click on "your project" in Eclipse EE Project Explorer 2 Click on Properties 3 Click on Targeted Runtimes 4 Checkbox of the version you are currently working with 5 Apply and close

This should do the trick.

Esau answered 1/7, 2019 at 21:48 Comment(1)
You did not address question asked. OP refers to runtime env (tomcat), toolchain (eclipse) is out of discussion here.Whippletree
B
-2

Make sure you import the right annotation, because I had the same problem as you.

javax.servlet.annotation.*

Butcherbird answered 23/10, 2013 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.