Google App Engine(2)Java Start and Project

Google App Engine(2)Java Start and Project



We need to use war directory instead of war archive file for app engine SDK.



The Project Directory
The structure of the project is going to be like this:

Guestbook

     src/

     war/

          WEN-INF     /

               lib/

               classes/



Almost the same as I am working in normal web project.



As I am using eclipse plugin, so I can just create a new project there based on the plugin.

I just type the project name and package declaration, place the project in this directory /Users/carl/work/appengine.



Base on my long term Java working experience, I think the below is the common Java Servlet work.



The Servlet Class
An HTTP servlet is an application class that can process and respond to web request.



Follow the document, it is just a class implement the HttpServlet API and overwrite the doGet method as follow:

package com.sillycat.sample.guestbook;



import java.io.IOException;



import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;



public class GuestbookServlet extends HttpServlet {



private static final long serialVersionUID = -8974156249244283590L;


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



The web.xml File
Make my own servlet work in web.xml. Web.xml is something just like the routes or URL mapping.

…snip...



<servlet>
     <servlet-name>guestbook</servlet-name>
     <servlet-class>com.sillycat.sample.guestbook.GuestbookServlet</servlet-class>
</servlet>
<servlet-mapping>
     <servlet-name>guestbook</servlet-name>
     <url-pattern>/guestbook</url-pattern>
</servlet-mapping>
<welcome-file-list>
     <welcome-file>index.html</welcome-file>
     </welcome-file-list>
</web-app>



The app engine-web.xml File
Additional configuration file is named appengine-web.xml and it is along with web.xml.

The configuration detail is here https://developers.google.com/appengine/docs/java/config/appconfig



I only configure my_app_id in application entry first.



Running the Project
Just run on eclipse plugin, but I got this error messages.

Error Message:
[ERROR] Unable to find 'com/sillycat/sample/guestbook/Guestbook.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?

[ERROR] shell failed in doStartup method



Error Message:
Missing required argument 'module[s]'



Solution:
The problem came when I create the project, I should pay attention to the option when I create projects. I should not select Google Web Toolkit, but only select Google App Engine.



Testing the Application

I can verify my application with this URL on my local browser then.

http://localhost:8888/guestbook



And the admin console URL is as follow:

http://localhost:8888/_ah/admin



References:
https://developers.google.com/appengine/docs/java/gettingstarted/creating

https://developers.google.com/appengine/docs/java/config/appconfig

http://stackoverflow.com/questions/8628429/google-app-engine-missing-required-argument-modules


猜你喜欢

转载自sillycat.iteye.com/blog/1764128