RSS:
Publications
Comments

Google AppEngine + IntelliJ, a Step-by-Step Guide

Setting up a new Google AppEngine project in IntelliJ is easy-peasy once you know how. Here’s how:

Project Setup

  1. Create project from scratch
    • type: Java Module
    • enable creation of source folder src
    • check Web Application in the “select technologies” window
  2. Configure project structure
    • Project SDK should be 1.6 (though 1.5 should work too)
    • Add dependency to library Google App Engine (containing appengine-tools-api.jar)
  3. Create config file
    • Create appengine-web.xml in WEB-INF with the following contents:
      <?xml version=”1.0” encoding=”utf-8”?>
      <appengine-web-app xmlns=”http://appengine.google.com/ns/1.0”>
      <application></application>
      <version>1</version>
      </appengine-web-app>
    • If you know what application name you should use, go ahead and fill it in.
  4. Create servlet
    • Right click project root, choose New -> Servlet
      This will create servlet class and update web.xml as needed.
    • Add a servlet mapping in the Assembly Descriptor tab.
      NOTE: Make sure the URL Pattern starts with a slash (/).
    • In the servlet’s doGet method, add the following:
      response.setContentType(“text/plain”);
      response.getWriter().println(“Hello, world!”);
  5. Create runner
    • Create new application configuration
    • Main class: com.google.appengine.tools.KickStart
    • Program parameters:
      com.google.appengine.tools.development.DevAppServerMain out\exploded\[your-project-name]Web
    • Environment variables:
      SDK_LIB=C:\lib\appengine-java-sdk\lib
      SDK_CONFIG=C:\lib\appengine-java-sdk\config\sdk
      (where it is assumed that google app engine SDK is located at C:\lib\appengine-java-sdk)
  6. Open page in browser
    • Navigate to http://localhost:8080/[your-url-pattern]
    • NOTE: To stop/restart the app, use Exit (exit) rather than Stop. Otherwise Jetty will keep running in the background.

Deploying the application

  1. Update the <application> tag in appengine-web.xml so it contains the Google app-id of your project.
  2. Upload to server.
    • If you have set up an external tool (described below), simply invoke the tool from Tools > Google App Engine > Deploy
    • Otherwise, perform the following steps to deploy manually:
      • Open a command line window
      • Navigate to the app-engine’s bin folder
      • Enter: appcfg.cmd update [full-path-to-intellij-project-root]\out\exploded\[your-project-name]Web
    • Enter Google account info when prompted.
    • NOTE: If appcfg.exe reports it cannot find javac.exe, it may be necessary to edit the appcfg.cmd file:
      Instead of invoking “java” (which is specifying whichever java happens to be on your system path), use the fully qualified path of the 1.6 JDK’s java.exe.
  3. Open page in browser
    • Navigate to http://[your-app-id].appspot.com/[your-project-name]Web

Setting up a new External Tool in IntelliJ

  1. Open the Settings menu (Ctrl+Alt+S) and click External Tools under IDE Settings.
  2. Click Add and use the following properties:
    • Name: Deploy
    • Group: Google App Engine
    • Description: Deploy to Google App Engine
    • Menu: “Main menu” checked
    • Open console: checked
    • Synchronize files after execution: checked
    • Program: C:\lib\appengine-java-sdk\bin\appcfg.cmd
    • Parameters: update $ProjectFileDir$\out\exploded\$ProjectName$Web
    • Working directory: C:\lib\appengine-java-sdk\bin

blog comments powered by Disqus