Setting up a new Google AppEngine project in IntelliJ is easy-peasy once you know how. Here’s how:
Project Setup
- Create project from scratch
- type: Java Module
- enable creation of source folder src
- check Web Application in the “select technologies” window
- 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)
- 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.
- Create appengine-web.xml in WEB-INF with the following contents:
- 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!”);
- Right click project root, choose New -> Servlet
- 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)
- Open page in browser
- Navigate to http://localhost:8080/[your-url-pattern]
- NOTE: To stop/restart the app, use Exit (
) rather than Stop. Otherwise Jetty will keep running in the background.
Deploying the application
- Update the <application> tag in appengine-web.xml so it contains the Google app-id of your project.
- 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.
- Open page in browser
- Navigate to http://[your-app-id].appspot.com/[your-project-name]Web
Setting up a new External Tool in IntelliJ
- Open the Settings menu (Ctrl+Alt+S) and click External Tools under IDE Settings.
- 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
