Helma Logo
main list history
previous version  overview  next version

Version 15 by hannes on 19. May 2009, 14:45

<b>NOTE: this guide is out of date already. The servlet name has changed to org.helma.jack.JackServlet, and the servlet parameters to moduleName, functionName, and helmaHome, respectively. I'll update this page as soon as the dust has settled. Sorry for the inconvenience and thanks for checking out Helma NG!</b>

With Google's *announcement|http://googleappengine.blogspot.com/2009/04/seriously-this-time-new-language-on-app.html* of *Java support|http://code.google.com/appengine/docs/java/overview.html* for App Engine there is all of a sudden a very attractive new option for hosting Java based web applications. Of course my first impulse was to check if it would run *Rhino|http://www.mozilla.org/rhino/* and Helma NG (I had little hopes for Helma 1 as it runs a lot of background threads and relies heavily on relational or file based database backends, both of which are not available on App Engine).

To my surprise, Rhino works perfectly out of the box, and I only had to make a few changes to Helma NG to get the demo app *running on App Engine|http://helma-ng.appspot.com/*. This is somewhat in contradiction with what *others have found|http://olabini.com/blog/tag/gae/*, and I discovered only later that I was partly lucky for not stomping on any SecurityExceptions, but on the other hand it's by virtue of Rhino not doing a lot of tricks under the hood, and Helma NG doing all its file reading through a unified *resource framework|http://github.com/hns/helma-ng/tree/10f5c896b0e9d9e2193ee24174d084965400520f/src/org/helma/repository*.

This article covers two options, one using the Helma NG webapp framework, and one using the *Jack|http://github.com/tlrobinson/jack/tree/master* interface for JavaScript web applications. Both are currently unfinished and subject to change, but it's enough to get your feet wet.

=== Prerequisites: Installing App Engine SDK and Helma NG

First, install the App Engine SDK for Java as described on the *Google pages|http://code.google.com/appengine/docs/java/gettingstarted/installing.html*. Whether you use the Eclipse plugin or the command line SDK shouldn't make a difference. I'm using Eclipse, but things should work in a similar fashion with the command line SDK.

Next, you need Helma NG, which is effectively Rhino with a thin layer of server-related functionality on top. Helma NG currently comes with its own copy of Rhino as we are using some experimental JS 1.8 features, but this may change as soon as these features are included in a Rhino release.

There hasn't been a release of Helma NG in recent times, so you have to You can *download the latest release|http://github.com/hns/helma-ng/downloads* or get it a snapshot from either *Subversion|https://dev.helma.org/svn/helma-ng/trunk* or *Git|http://github.com/hns/helma-ng/tree/master*. For Subversion, the command is:

<tt style="font-weight:bold;color:#d33;">svn co https&#58;//dev.helma.org/svn/helma-ng/trunk/ helma-ng</tt>

For Git:

<tt style="font-weight:bold;color:#d33;">git clone git://github.com/hns/helma-ng.git</tt>

You need *Apache Ant|http://ant.apache.org/* to build Helma NG. Change to the helma-ng directory you just checked out and run ant it with the "jar" target:

<tt style="font-weight:bold;color:#d33;">ant jar</tt>

If this worked then you should now have a file called lib/helma.jar.

=== Creating a new Web App project

Once you have everything in place, create a new, empty App Engine application. With the Eclipse plugin you do this using the new project wizard and selecting "Web Application Project" in the Google category. This will ask you for a project name and a package name. The package name doesn't matter unless you plan to write Java code, but it is required so just enter anything.

The new project should have two subdirectories, "src" and "war". Again, the src dir is only relevant for Java code, as we'll put our JavaScript code directly in war/WEB-INF and our jar files in war/WEB-INF/lib.

Next, copy over some jar files from the Helma NG lib directory to the war/WEB-INF/lib of your project. You'll probably need the following:

* <tt style="font-weight:bold;color:#d33;">lib/js.jar</tt>
* <tt style="font-weight:bold;color:#d33;">lib/helma.jar</tt>
* <tt style="font-weight:bold;color:#d33;">lib/log4j-1.2.15.jar</tt>

App Engine has its own web server of course, so you don't need the jetty or servlet jar files.

From here, you have two options: Run an app using the Helma NG webapp framework, or one using the *Jack|http://github.com/tlrobinson/jack/tree/master* interface. The first is currently subject to major redesign, while the latter is rather unfinished, so choose your tools wisely :-)

=== Running Helma NG apps

To run the Helma NG *demo application|http://helma-ng.appspot.com/* follow these steps:

# Copy over the modules directory from the Helma NG directory to the war/WEB-INF so that the resulting directory is called <tt style="font-weight:bold;color:#d33;">war/WEB-INF/modules</tt>.
# Copy the demo app itself from apps/demo to war/WEB-INF so that the resulting directory is called <tt style="font-weight:bold;color:#d33;">war/WEB-INF/demo</tt>. Note that the demo app contains a symbolic link, which is not supported by Google App Engine. Copying files with <tt style="font-weight:bold">cp -rL</tt> will take care of dereferncing the link.
# Copy or move the static directory from within the demo app two levels up to the war directory (war/static).
# Edit the <tt style="font-weight:bold;color:#d33;">web>war/WEB-INF/web.xml</tt> file in the war/WEB-INF directory to look *like this|http://dev.helma.org/static/files/3318/web-helmaorg/static/files/3318/web.xml*, or just copy download and overwrite the file if you are lazyfile.

That's it - save all your changes and click on the green Run button in Eclipse or run the dev_appserver.sh script to start the development server. If everything worked as planned you should be able to access the *demo app|http://helma-ng.appspot.com/* on http://localhost:8080/.

<b>Note:</b> The Helma webapp framework is currently in state of major redesign. If you're looking for a stable development platform I recommend to wait until the upcoming 0.3 release.

=== Running Jack apps

Helma NG provides a servlet to run uses *Jack|http://github.com/tlrobinson/jack/tree/master* applications without using Helma's own module to as web application connector, so you are not bound to use the Helma webapp infrastructure. In this modeIf you prefer, you get can use Helma NG as a relatively naked JavaScript runtime that is container for Jack applications fully compliant to compatible with the *ServerJS Securable Modules proposal|https://wiki.mozilla.org/ServerJS/Modules/SecurableModules*.

Copy over The setup is much the modules directory from same as with the Helma NG directory to the war/WEB-INF so that the resulting directory is called war/WEB-INF/modulesdemo application, but for a minimal runtime, just copy only that you point the following two files:JackServlet to your own Jack web appliction in <tt style="font-weight:bold;color:#d33;">war/WEB-INF/web.xml</tt>.
* <tt style="font-weight:bold;color:#d33;">modules/global.js</tt> - for basic functionality such as module and resource loading
* <tt style="font-weight:bold;color:#d33;">modules/helma/jack.js</tt> - for helper functions used by the jack servlet

ThenFor example, create a directory called <tt style="font-weight:bold;color:#d33;">war/WEB-INF/myapp</tt>, and assuming you have the following simple Jack application in that directory a file called <tt style="font-weight:bold;color:#d33;">main>app/main.js</tt> with the following content:js</tt>:

  function handler(env) {
    return [200, {"Content-Type": "text/plain"}, ["Hello World!"];]];

FinallyYou would then set the <tt style="font-weight:bold;color:#d33;">modulePath</tt> servlet init-parameter in web.xml to <code>app</code>, edit <tt style="font-weight:bold;color:#d33;">web.xml</tt> file in war/WEB-INF >moduleName</tt> to look *like this|http://dev.helma.org/static/files/3318/web-jack.xml*<code>main</code>, or just download and overwrite the file<tt style="font-weight:bold;color:#d33;">functionName</tt> to <code>handler</code>.

Save all your changes and click on After starting the green Run button in Eclipse to start the development server. You server you should now see be able to access your minimal Jack app on at http://localhost:8080/.

If you don't want or need Helma NG, another option for running Jack on App Engine is using the JackServlet Tom Robinson's original *Jack library|http://jackjs.org/*.

<b>Note:</b> Jack support in Helma NG is very new, and thus quite incomplete. Feel welcome to close any gaping holes!