Recently Google released an early look of AppEngine for Java. It includes an Eclipse plugin for developing with AppEngine Java SDK. I wanted to check is it possible to develop AppEngine Java application using NetBeans
- Sun JDK 1.6.0_12
- NetBeans 6.7 M2 (pre-release)
Opening projectLet's start with basic AppEngine demo Guestbook. It's located in demos/guestbook directory of gae-sdk-java.
Create project wizardStart the wizard with File|New Project.
Step 1Select options like this:
Step 2Enter the location of the project in the edit box, or click browse:
The rest of the lines will be filled automatically.
Step 3Leave the default options on the "Build and Run Actions" page.
Step 4Don't change anything on the "Web Sources" page.
Step 5Click "Next" on "Source Package Folders" page.
Step 6Click "Add JAR/Folder" on the "Java Sources Classpath" page and add all jars located in war/WEB-INF/lib folder under guestbook root:
Click Finish to leave default settings on the last two pages.
Fixing classpathThe resulting project will look like this:
Two Servlet files have errors because NetBeans has limited abilities on parsing ant build files. It could not extract the compile time dependencies from
build.xml, so we pointed to WEB-INF/lib libraries at Step 6. But one of the compile dependencies (Servlet API jar) is located outside of the project tree. It's because this jar is supplied by the application server. In my pre-release version of NetBeans the UI is not able to use dependencies outside of the project tree, but it's easy to work around.
Edit project.xmlPress Ctrl-F2 or select Window|Files to switch to files panel. You see all files under your project root:
Click on + sign to open nbproject, right-click on project.xml and select Edit. This opens internal NetBeans project file which contains all the settings we selected in the wizard. Find line which contains
<classpath>element near the end of the file. Go to the end of the line and add the path Servlet API jar. This jar is located in lib/shared folder under the Google AppEngine Java SDK folder, in my case the full path was
C:\work\appengine-java-sdk-1.2.0\lib\shared\geronimo-servlet_2.5_spec-1.2.jarPress Ctrl-S to save the
project.xmlfile and return to Projects pane (press Ctrl-1). Now NetBeans is happy and no errors are reported.
Running the applicationYou can run this application as you run any project in NetBeans. If this is the main project, simply press F6. When the project is running, you will see the following line in the Output window:
The server is running at http://localhost:8080/. You can enter this URL in a browser and start using the Guestbook application. In this post you can find out how to debug AppEngine java web application using NetBeans.