Daily Archives: June 15, 2009

Initial Hacking of Java App Engine on Macintosh

I started building my first Java App Engine Application. I added the plug in to Eclipse and created my first application. Make *sure* to uncheck “Use Google Web Toolkit” unless you really want it. If you are just making a simple servlet – you probably don’t want GWT.

Other than that, it is amazingly simple. When I skimmed the documentation it appeared that not much changed except for the addition of WEB-INF/appengine-web.xml file – and that was pretty much it. The rest is pretty much pure servlet. Sweet.

When you use the Run, option it runs Jetty which puts your application at / (i.e. not /servletname). Somehow, there is no way to stop Jetty when you need to recompile a class and want a full re-deploy. Now I don’t know how well Jetty does with hot-deploy – maybe you just recompile. But for us Tomcat refugees we want to restart once in a while.

Here is how I do it with my Mac:

ps -ef | grep geronimo | grep -v grep | awk '{print "kill " $2}' | sh -x

Then just run your app again from Eclipse.

The next thing that went wrong is something strange with the Mac Java VM and the harsh security confines of the App Engine – HMAC signing using a native library on the Mac – so you get this sweet traceback:

java.security.AccessControlException: access denied (java.lang.RuntimePermission loadLibrary.keychain)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at com.google.appengine.tools.development.DevAppServerFactory
at com.apple.crypto.provider.HmacCore.(HmacCore.java:26)
at javax.crypto.Mac.init(DashoA12275)
at net.oauth.signature.HMAC_SHA1.computeSignature(HMAC_SHA1.java:74)

Now this is *not* a problem on a deployed Java Application on the Google production environment – but it makes testing kind of less fun. So the workaround is make the following setting:

Eclipse -> Propject -> Properties -> Run/Debug Settings -> select your target -> Edit -> Arguments -> VM Arguments

-D--enable_all_permissions=true

Now you might get in trouble because you end up with something working on your mac that fails on the GAE production because it bypasses the Java policies – but at least you can HMAC on your Macintosh.