Wednesday, April 8, 2009

Rhino JavaScript working on App Engine Java Edition

I was super-excited this morning, when I saw the announcement that Google had released a Java version of their App Engine environment. My heart sank a bit when I read that they had a class white-list for security reasons, and told myself that I wouldn't be surprised if that means that you cant run Server-side JavaScript at all.

However, after reading Ola Bini's quick article on how to enable JRuby, I felt that it might be doable, after all, JS doesn't even have Threads (which more or less thankfully are disabled in GAE). It _should_ work.  

So I went and downloaded the eclipse plugin, created a new project, which came with its own "Hello World" servlet and dropped the Mozilla labs JS version 1.7 jar (from the Dojo Ajax Toolkit's util/shrinksafe folder) into the lib/ folder of the GAE project, added some paths here and there -- and it worked.

I tried something really simple like this;


String s = "var foo = {foo: 17, bar: 4711};;";

Object result = cx.evaluateString(scope, s, "", 1, null);



And out I got a 



I just saw that Google has limited the Java GAE SDK for the 10 first to register. I guess Sweden was the right place to be :)  If you want to see my sample project, you can download it from here;



Roberto Saccon said...

Cool, Peter, now we got what we have been waiting for ! Was offline yesterday, and today, after googeling for appengine and rhino this was the top entry !

Ivan said...

i almost can't wait to get home to try this out. unfortunately, i'll have to :(

Peter Svensson said...

@Roberto Saccon :) That's good to hear. Now I'll just try to find time to read in a file and to port the REST server interface I did for Babble/10gen.

@Ivan: Work is soon over! Time to play.

main said...

Nice to see another language work.

I wrote aboutn bringing up a sinatra app.
You can find it here.


Hannes Wallnoefer said...
This comment has been removed by the author.
Hannes Wallnoefer said...

It runs very well indeed. If you're seriously interested in running Rhino on App Engine, make sure you check out Helma NG, a compact yet powerful server-side JS runtime based on Rhino.

Peter Svensson said...

@Hannes Wallnoefer: You're right of course. I hadn't even thought of that yet, having a lot to do. It all depends on what kind of magic Helma does with Java under the hood, since the GAE/J has a class whitelist. No, for example, and so on. No Threads stuff. But either it would work directly, or it will be possibly to do a 'Helma lite' och 'Helma GAE' version, I'm sure.

Thanks for the idea!

Maksim Lin said...

Peter, I think what Hannes meant is that helma-ng is already running well on App Engine.

Hannes has posted a howto on itAnd in his comment above is the link to the demo app running on appspot.

Peter Svensson said...

@Makrim Lin: You are right, of course. Maybe it wold help if I actually read what I was commenting :)

Anonymous said...

i have gone through your site information and it is the sae oppertunity that i was looking for thr facilities,
the process that what you are offering , are perfectely matched to my expection, very soon you will get
responce from my side

online job

javieth said...

JavaScript is a good program and very easy to use. I don´t like a complex program. I prefer javascript because i consider it like a device very eficient and it have a good quality.
I always looking for the quality that is why i prefer to buy viagra because i always have a great result in my sexual life.