2015/02/17

How to create Google App Engine eclipse project with frontend module and backend module

In this article, i will create a Google App Engine eclipse project support frontend module and backend module.
Why i doing this, because GAE console keep annoying me whit this.

"This application uses Backends, a deprecated feature that has been replaced by Modules, which offers additional functionality. Please convert your backends to modules as described at: Python | Java | Go"

Step1:Prepare eclipse environment
Switch eclipse to Java EE perspective.


Step2:Create new Enterprise Application Project

Setting Project name and target runtime.


Select existed modules.


Setting Google App engine Application ID.


You may has this error message after create a new project.
"vc-complex-type.2.4.b: The content of element 'application' is not complete. One of '{"http://java.sun.com/xml/ns/javaee":display-name, "http://java.sun.com/xml/ns/javaee":icon, "http://java.sun.com/xml/ns/javaee":module}' is expected."


Change the xsi:schemaLocation content from
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
       http://java.sun.com/xml/ns/javaee/application_5.xsd">


To
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee;
                     http://java.sun.com/xml/ns/javaee/application_5.xsd">



Step3:Create new Dynamic Web Project for frontend default module

Setting Project name and add this project to EAR project.


Setting source folder.


Configure web module setting. Set the Context root as "default", because GAE need a default front module name as "default".


Configure Google App Engine. Again, GAE needs a module named "default".


The default frontend module is created.


Step4:Create new Dynamic Web Project for backend module

Setting Project name and add this project to EAR project.


Setting source folder.


Configure web module setting.


Configure Google App Engine.


The modules are created.




Modify the GAEJModuleBackend/WebContent/WEB-INF/appengine-web.xml to support the backend instance.
 
 

  gaejmoduletest
  backend
  2
 true

  
  B1
  
    11
    10m
  
  
  
  
    
  

Create background threads to run the instance in backend.We modify the GAEJModuleBackendServlet.java.
public class GAEJModuleBackendServlet extends HttpServlet 
{
 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException 
 {
  Thread thread = ThreadManager.createBackgroundThread(
  new Runnable() 
  {
   public void run() 
   {
    try 
    {
     Thread.sleep(10);
    } 
    catch (InterruptedException ex) 
    {
     throw new RuntimeException("Exception:", ex);
    }
   }
  });
  thread.start();
 }
}


Step4:Setting remote server

Click the link to create remote server.


Define a new server.


Configure server.


Add server.


We created a App Engine localhost server.


Step5:Uploading to Google App Engine

No comments:

Post a Comment