pAkY88
pAkY88

Reputation: 6294

Tomcat: Class not found exception

I'm developing a servlet running on Tomcat 6 using Eclipse as IDE.

The main path of the web application is "Calcolatrice" and the name of the servlet id "Calcolatrice" too.

When I try to execute a simple get operation on the servlet the following exception is throwed:

javax.servlet.ServletException: Wrapper cannot find servlet class as.unibo.Calcolatrice or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:680)

root cause

java.lang.ClassNotFoundException: as.unibo.Calcolatrice
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:680)

What I cannot understand is why the package where is the servlet is "as.unibo.polac.server" but Tomcat searches it in another package "as.unibo".

Which could be the reason of this problem?

[EDIT]

This is the content of my web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Calcolatrice</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>Calcolatrice</display-name>
    <servlet-name>Calcolatrice</servlet-name>
    <servlet-class>as.unibo.Calcolatrice</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Calcolatrice</servlet-name>
    <url-pattern>/Calcolatrice</url-pattern>
  </servlet-mapping>

</web-app>

Is it correct?

Upvotes: 0

Views: 4803

Answers (1)

Harry Joy
Harry Joy

Reputation: 59650

Because your servlet is in as.unibo.polac.server package your web.xml should be:

....
  <servlet>
    <description></description>
    <display-name>Calcolatrice</display-name>
    <servlet-name>Calcolatrice</servlet-name>
    <servlet-class>as.unibo.polac.server.Calcolatrice</servlet-class>
  </servlet>

.....

The class path is wrong in your web.xml. Update it.

Upvotes: 3

Related Questions