appengine-silver-120x30.gifThis is a short post about the new java support for google appengine. The Basic steps are described very well at google, check the getting started manual. Here I just describe my experiences with my first java based application for google appengine. I concentrate on the usage of intellij. In coming posts I will create the same application as the one I used for my previous post: using google appengine.

Quick intro

For an eclipse user there are other steps to get things done. There is something like a plugin that might work depending on other plugins that you have installed and some eclipse magic. Sorry, I am a non believer. I prefer another IDE.

So for the non eclipse guys you need to download a zip file with all the resources you need to start working with the new sdk. I create a symbolic link to the downloaded version, that way it is easy to change for future releases.

ln -s appengine-java-sdk-1.2.0/ appengine-java-sdk

As the getting started suggest, you can now test your infrastructure with one of the provided demo’s.

./appengine-java-sdk/bin/dev_appserver.sh appengine-java-sdk/demos/guestbook/war/

Open your browser and go to the link http://localhost:8080/. You should see the following screen.

Screendump_google_demoapp.png

Oke, time to take the next step. The structure for an application is the same as for a web archive. There is a catch, you cannot use the war file itself, you need the exploded directory. Luckily it is very easy to do this with maven or with Intellij. Those eclipse users that are still reading this post have an easier life. They can use the wizard from the google plugin. I start off with a normal intellij java project with a web facet.

Google app engine works with servlets, so we need to create a servlet, we also need to add this servlet to the web.xml. Since the code I used is at the google tutorial, I’ll not repeat it here.

Google appengine needs an additional xml configuration file. This file is called and it looks like this:

<?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>

Next step in intelliJ is to make the module, you can find the exploded war in the folder out > exploded > GoogleAppEngineGuestbookWeb. Using this exploded folder you can start the appengine. We need a runner in intellij. This is not very hard to do.There are two important steps. The first step is to create a library that you add to your module. This library contains one jar file : appengine-tools-api.jar. You can find this jar in the distribution of google appengine you downloaded. If you do not know how to add a library, open the module settings (apple: command + ;). Create a new library and when asked say yes to add it to your module. The screen should look like the following image.

Intellij_configure_library.png

Next up is configuring a runner. Create a runner of type Application. Now use the script dev_appserver.sh, that you can find in the distribution of google appengine in the bin folder. We need to set the environment variables, the program parameters and the main class.

Main class

com.google.appengine.tools.KickStart

Program parameters


com.google.appengine.tools.development.DevAppServerMain
out/exploded/GoogleAppEngineGuestbookWeb

Check the second parameter, this is the location of the exploded war file that intellij creates for you.

Environment variables


SDK_LIB=YOUR_GOOGLE_APPENGINE_HOME/appengine-java-sdk/lib
SDK_CONFIG=YOUR_GOOGLE_APPENGINE_HOME/appengine-java-sdk/config/sdk

The screen for configuring your runner now looks like this

Intellij_configure_runner.png

That is about it, now you can run the application. After running, the output in the console is:


2009-04-08 23:53:44.332 java[3557:10b] [Java CocoaComponent compatibility mode]: Enabled
2009-04-08 23:53:44.333 java[3557:10b] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
The server is running at http://localhost:8080/

Now you can point your browser to the following url : http://localhost:8080/guestbook and Hello world should be yours.

Deployment

Before you can upload, you need to register yourself with google. If you already have an appengine account, you can request the java beta admittance. After that create a new google appengine application in your domain. That’s it, remember the name of the app you just registered because you need it in the next step.

Next up is the actual deployment, this is not a very complicated process. You can use the same directory that you use for the test server. Be sure to change the file appengine-web.xml. Add your name of the application to the application tag. If your using intellij do not forget to make the module. In my case this application name is doingjava. Now all you need during the upload is your google account name and password. Next is the command to do the actual upload


./appengine-java-sdk/bin/appcfg.sh update PATH_TO_YOUR_INTELLIJAPP/out/exploded/GoogleAppEngineGuestbookWeb

In my case you can check if it works on the following url: http://doingjava.appspot.com/guestbook.

Conclusion

This is not a conclusion on the usage of google appengine and java. For me it was an exercise to create a project in intellij and be able to use the google mock webapp runner. This seems to work nicely. The future will bring more posts about google appengine which now support java.

I do want to stress this is not a best practice, I advise to use an ant script that you can get from google at the following url. http://code.google.com/appengine/docs/java/tools/ant.html

Some important url’s

Java on Google app engine with intelliJ
Tagged on:             

8 thoughts on “Java on Google app engine with intelliJ

    • April 10, 2009 at 7:01 am
      Permalink

      To me the biggest thing is that you cannot use threads, I haven’t seen if ThreadLocal is supported. That might have a problem as well.

  • April 9, 2009 at 11:42 am
    Permalink

    When I end the runner the server keeps running in the background.. any way to kill it automaticaly?

    • April 9, 2009 at 7:40 pm
      Permalink

      I have tried it myself, but I do not see the problem. My java process is killed with the runner. What OS are you using?

  • April 8, 2009 at 11:41 pm
    Permalink

    Interesting Jettro; what does the app engine provide, and what are the restrictions?

    What Im really asking is: how does it differ from any other servlet container, and what does the API provide?

    I better go look at the links provided…

    • April 9, 2009 at 6:24 am
      Permalink

      There are a few things important, I think the intro of the google docs contains them all.

      With App Engine, you can build web applications using standard Java technologies and run them on Google’s scalable infrastructure. The Java environment provides a Java 6 JVM, a Java Servlets interface, and support for standard interfaces to the App Engine scalable datastore and services, such as JDO, JPA, JavaMail, and JCache. Standards support makes developing your application easy and familiar, and also makes porting your application to and from your own servlet environment straightforward.

Comments are closed.