Friday, April 17, 2009

AppEngine project on NetBeans

This is a beginning of discussion, continued here

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


  1. Sun JDK 1.6.0_12
  2. NetBeans 6.7 M2 (pre-release)
  3. gae-java-sdk-1.2.0

Opening project

Let's start with basic AppEngine demo Guestbook. It's located in demos/guestbook directory of gae-sdk-java.

Create project wizard

Start the wizard with File|New Project.

Step 1

Select options like this:

Step 2

Enter the location of the project in the edit box, or click browse:

The rest of the lines will be filled automatically.

Step 3

Leave the default options on the "Build and Run Actions" page.

Step 4

Don't change anything on the "Web Sources" page.

Step 5

Click "Next" on "Source Package Folders" page.

Step 6

Click "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 classpath

The 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.xml

Press 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.jar

Press Ctrl-S to save the project.xml file and return to Projects pane (press Ctrl-1). Now NetBeans is happy and no errors are reported.

Running the application

You 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.


Anonymous said...

Thanks for the post; at this point, would you recommend sticking with Eclipse and the GAE plugin?

Andrew Skiba said...

If you don't have special reasons to use NetBeans, Eclipse plugin for GAE makes things a lot easier.

stera said...

This is cool.
But I found that samples of Google App Engine can start,there is no way to stop Jetty web server.
How do you stop it?

Andrew Skiba said...

If server is launched from NetBeans, I could not find a better way to stop it then to kill server's JVM. So I ended up compiling in NetBeans and launching the server from command line, then Ctrl-C works as usual.

stera said...

Stop Jetty Server using "Java VisualVM" and "TASKKILL" Look at this blog site:

Andrew Skiba said...

Good point! Another useful utility is JDK's jps which lists all running JVMs. I did not know about TaskKill and used process explorer on unlucky days I had to use Windows.

stera said...

I got a comment from "NetBeans Profiler".

You can stop Jetty Server directly from VisualVM. Use 'Kill Application' VisualVM plugin, which is available on VisualVM Plugin Center.
There was no need to use "taskkill" command.

Andrew Skiba said...

Oh, that would be useful. Thank you!

Blaza said...

Hi, what's about to use this NB plugin for App Engine development in NetBeans? The plugin supports local development, debugging, deployment and also hints in editor.

Andrew Skiba said...

That's interesting! I'll try it.

franci said...

thanks Andrew, I've found this post very useful, I prefer netbeans to eclipse for developing

Andrew Skiba said...

Glad it helps, Franci! I prefer NetBeans, too. Did you try the plugin from kenai project?

shashi said...

i have jdk1.5.0_11 installed,is it ok to use in netbean6.7 or i must have jdk1.6.0_12 for google app engine to run

Andrew Skiba said...

Shashi, I used jdk 6 but I think it should work with jdk 1.5, too. Did not try it though.