1

Just created a brand new project with Eclipse June 4.2 Use Google App Engine SDK 1.7.4

Eclipse create a Servlet

public class ClockServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/plain");
        resp.getWriter().println("Hello, world");
    }
}

and a simple web.xml

    <servlet>
    <servlet-name>Clock</servlet-name>
    <servlet-class>clock.ClockServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Clock</servlet-name>
    <url-pattern>/clock</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

When i deploy it i get the generic HTML error page: Error: Server Error and from the logs i get:

    EXCEPTION java.lang.ClassNotFoundException: clock.ClockServlet
at com.google.appengine.runtime.Request.process-0925dcee3db2e16a(Request.java)

But the servlet exists and the web.xml is correct Where am i wrong?

tnx

alessalessio
  • 1,224
  • 1
  • 15
  • 28
  • Show us the complete source code of the servlet (from line 1 to last line). – JB Nizet Dec 27 '12 at 16:39
  • package clock; import java.io.IOException; import javax.servlet.http.*; @SuppressWarnings("serial") public class ClockServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.getWriter().println("Hello, world"); } } – alessalessio Dec 27 '12 at 16:44

2 Answers2

3

Well, seems that Servlet and Web.xml were correct but there was missing a tag that is a must for using Google App Engine. I wonder why it is not underlined and written with capital letters inside documentation.

Tag is <load-on-startup>1</load-on-startup>

Please refer to Java Application Configuration

Each custom servlet must be loaded on startup to let GA Engine instatiate the class and accept requests. Here is the final web.xml to use for deploying the application in GAE

    <servlet>
    <servlet-name>Clock</servlet-name>
    <servlet-class>clock.ClockServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Clock</servlet-name>
    <url-pattern>/clock</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
alessalessio
  • 1,224
  • 1
  • 15
  • 28
0

Hi please have a look at: ClassNotFoundException with ServletContextlistener

check the issue (second one) with the servlet-api

Community
  • 1
  • 1
Nadav Finish
  • 1,120
  • 9
  • 7
  • This might be answer, but usually it's best to include at least the important part of the answer from the link ;-) – Uli Köhler Jan 29 '14 at 20:27