Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Tomcat in Eclipse, Error 500 ClassNotFound for servlet(java.lang.ClassNotFoundException: com.example.servlets.HelloServlet)
Tomcat in Eclipse, Error 500 ClassNotFound for servlet [message #539067] Wed, 09 June 2010 14:27 Go to next message
No real name is currently offline No real nameFriend
Messages: 6
Registered: June 2010
Junior Member
Hey, I've just been working on this tutorial here:

http://www.ibm.com/developerworks/opensource/library/os-ecli pse-tomcat/index.html

It has been pretty good and I've got the jsp page to show the time but when I try going to the
HelloServlet I get the error 500.

http://localhost:8080/FirstWebProject/HelloServlet

Error Report
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Wrapper cannot find servlet class com.example.servlets.HelloServlet or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorRepo rtValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAd apter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Proce ssor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHand ler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoin t.java:489)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.ClassNotFoundException: com.example.servlets.HelloServlet
org.apache.catalina.loader.WebappClassLoader.loadClass(Webap pClassLoader.java:1516)
org.apache.catalina.loader.WebappClassLoader.loadClass(Webap pClassLoader.java:1361)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorRepo rtValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAd apter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Proce ssor.java:852)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHand ler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoin t.java:489)
java.lang.Thread.run(Unknown Source)


web.xml file generated in my Eclipse web project

<?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>FirstWebProject</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>HelloServlet</display-name> 
    <servlet-name>HelloServlet</servlet-name> 
    <servlet-class>com.example.servlets.HelloServlet</servlet-class> 
  </servlet> 
  <servlet-mapping> 
    <servlet-name>HelloServlet</servlet-name> 
    <url-pattern>/HelloServlet</url-pattern> 
  </servlet-mapping> 
</web-app> 



I'm using Tomcat 6. I've
made NO changes to ANY web.xml files, I simply followed that short basic tutorial step by step. My HelloServlet.java class is exactly the same as in the tutorial and is in the same package.
Could you please tell me why it can't seem to find the class?

Thanks heaps,

Smile
Re: Tomcat in Eclipse, Error 500 ClassNotFound for servlet [message #539119 is a reply to message #539067] Wed, 09 June 2010 16:52 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
On 6/9/2010 10:27 AM, frozen_monkey88@hotmail.com wrote:
> Hey, I've just been working on this tutorial here:
> http://www.ibm.com/developerworks/opensource/library/os-ecli pse-tomcat/index.html
>
>
> It has been pretty good and I've got the jsp page to show the time but
> when I try going to the HelloServlet I get the error 500.
> http://localhost:8080/FirstWebProject/HelloServlet
>
> Error Report
> type Exception report
> message
> description The server encountered an internal error () that prevented
> it from fulfilling this request.
> exception
> javax.servlet.ServletException: Wrapper cannot find servlet class
> com.example.servlets.HelloServlet or a class it depends on
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorRepo
> rtValve.java:102)
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAd
> apter.java:298)
> org.apache.coyote.http11.Http11Processor.process(Http11Proce
> ssor.java:852)
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHand
> ler.process(Http11Protocol.java:588)
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoin t.java:489)
> java.lang.Thread.run(Unknown Source)
>
> root cause
> java.lang.ClassNotFoundException: com.example.servlets.HelloServlet
> org.apache.catalina.loader.WebappClassLoader.loadClass(Webap
> pClassLoader.java:1516)
> org.apache.catalina.loader.WebappClassLoader.loadClass(Webap
> pClassLoader.java:1361)
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorRepo
> rtValve.java:102)
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAd
> apter.java:298)
> org.apache.coyote.http11.Http11Processor.process(Http11Proce
> ssor.java:852)
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHand
> ler.process(Http11Protocol.java:588)
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoin t.java:489)
> java.lang.Thread.run(Unknown Source)
>
> web.xml file generated in my Eclipse web project
>
> <?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>FirstWebProject</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>HelloServlet</display-name>
> <servlet-name>HelloServlet</servlet-name>
> <servlet-class>com.example.servlets.HelloServlet</servlet-class >
> </servlet> <servlet-mapping> <servlet-name>HelloServlet</servlet-name>
> <url-pattern>/HelloServlet</url-pattern> </servlet-mapping> </web-app>
>
> I'm using Tomcat 6. I've made NO changes to ANY web.xml files, I simply
> followed that short basic tutorial step by step. My HelloServlet.java
> class is exactly the same as in the tutorial and is in the same package.
> Could you please tell me why it can't seem to find the class?
> Thanks heaps,
> :)

There isn't any detail here that suggests why the HelloServlet class
isn't found. Details about the Tomcat support can be found in the
Tomcat FAQ[1]. As a first step, check under
"<your-workspace> /.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpweba pps/FirstWebProject/WEB-INF/classes/com/example/servlets "
and make sure HelloServlet.class exists.

Cheers,
Larry

[1] http://wiki.eclipse.org/WTP_Tomcat_FAQ
Re: Tomcat in Eclipse, Error 500 ClassNotFound for servlet [message #539214 is a reply to message #539119] Thu, 10 June 2010 02:16 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 6
Registered: June 2010
Junior Member
Hey Larry, thanks for your help. There wasn't any HelloServlet.class file created so I created an empty main method

public static void main(String[] args){};


inside HelloServlet.java then ran it as a Java application inside Eclipse to generate the HelloServlet.class file. I then put this class file in the WEB-INF directory and then it all worked fine.

Cheers
Re: Tomcat in Eclipse, Error 500 ClassNotFound for servlet [message #539343 is a reply to message #539214] Thu, 10 June 2010 13:03 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
On 6/9/2010 10:16 PM, frozen_monkey88@hotmail.com wrote:
> Hey Larry, thanks for your help. There wasn't any HelloServlet.class
> file created so I created an empty main method
> public static void main(String[] args){};
>
> inside HelloServlet.java then ran it as a Java application inside
> Eclipse to generate the HelloServlet.class file. I then put this class
> file in the WEB-INF directory and then it all worked fine.
>
> Cheers
>

Your project should contain a "build/classes" folder. It is under this
folder that Eclipse should compile your HelloServlet.java file. Is
there a "FirstWebProject/build/classes/com/example/servlets" folder
containing a HelloServlet.class file? Such a file should automatically
be copied to ".../wtpwebapps/FirstWebProject/WEB-INF/classes". You
shouldn't have to "put this class file in the WEB-INF directory".

Cheers,
Larry
Re: Tomcat in Eclipse, Error 500 ClassNotFound for servlet [message #539499 is a reply to message #539343] Fri, 11 June 2010 04:13 Go to previous message
No real name is currently offline No real nameFriend
Messages: 6
Registered: June 2010
Junior Member
Yes, there wasn't a .class file in the build/classes/<Mypackage> folder initially, after playing around with it that was the only thing I needed to get it working. I thought it was because I placed the .class file in the WEB-INF folder but I removed it and only had the .class file in that build.classes.<Mypackage> folder and it worked fine.

Cheers

[Updated on: Fri, 11 June 2010 04:14]

Report message to a moderator

Previous Topic:Making sense of Java EE and Galileo
Next Topic:Bug in stopping JBoss?
Goto Forum:
  


Current Time: Fri Mar 29 13:40:00 GMT 2024

Powered by FUDForum. Page generated in 0.02256 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top