Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SEVERE: Allocate exception for servlet <myservlet-name> java.lang.ClassNotFoundException: <myservlet> exception [duplicate]

When I use the following web.xml, my project runs fine and I can see "Hello World" getting displayed via index.jsp page. I am using Netbeans 7.4 and Apache tomcat 6.0.41

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
 </web-app>

However, when I created my own servlet and use the following web.xml,=

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

 <servlet>
    <servlet-name>TEST_Authenticate</servlet-name>
    <servlet-class>restapi.TEST_Authenticate</servlet-class>
</servlet>  
<servlet-mapping>
    <servlet-name>TEST_Authenticate</servlet-name>
    <url-pattern>/TEST_Authenticate</url-pattern>
</servlet-mapping>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>


    <scope>provided</scope>
</dependency>

I end up getting the following error in the Apache Tomcat Log:

Jul 24, 2014 9:36:14 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet TEST_Authenticate
java.lang.ClassNotFoundException: TEST_Authenticate
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:744)

I have checked the following post but still getting the errors.

Project Structure :

enter image description here

like image 906
John Avatar asked Sep 04 '25 16:09

John


1 Answers

First of all remove

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

from the web.xml and put it in your pom.xml if it is a Maven project.

Secondly, ClassNotFoundException is thrown when the class cannot be found in the specified location. In your case, as you have

<servlet-class>restapi.TEST_Authenticate</servlet-class>

So, I am assuming that you have a package of name restapi and under which you have the class TEST_Authenticate.

So, if it is a Maven project you should have scr/main/java/yourpackagename/yourClass and if it is a simple web-project then it should be like src/yourpackagename/yourClass.

like image 198
SparkOn Avatar answered Sep 07 '25 18:09

SparkOn