Google App Engine(2)Java Start and Project

本文介绍了使用 Java 在 Google App Engine 上开发应用的过程,包括项目目录结构、Servlet 类的实现及配置文件 web.xml 和 appengine-web.xml 的设置方法。此外,还解决了运行过程中遇到的错误并提供了本地测试的方法。
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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值