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}; foo.foo;";

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

resp.getWriter().println(Context.toString(result));

...

And out I got a 

17

:)

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;

http://genericwitticism.com/rhino.zip

Cheers,
PS

lala moulati ana9a maghribia

seo

 

Blogroll

Site Info

Text

telechargementz Copyright © 2009 WoodMag is Designed by Ipietoon for Free Blogger Template