Monday, August 31, 2009

e4 0.9 review - 02 - How to write a Helloworld JavaScript Bundle

e4 0.9 review - 02 - How to write a Helloworld JavaScript Bundle

Go on the next e4 .9 review blogging.

The e4 has introduced the "JavaScript framework" to demonstrate the flexibility of e4 language support. In the meantime, this e4 component makes the Eclipse much similar to the internet browser(like FF,Chrome,IE...). Yeah, it can be imagined that we get a heavy but high-performance internet client. The GEF/GEF3D with Javascript should beat mainstream Javascript libraries easily. Cool...Oh, it is a little unfair to compare the C/S structure to B/S...

One thing worried by me is that, in the JS framework diagram, one flow "e4 JS->Rhino->JVM" pass by the OSGI framework. It is a smell in the aspect of security. Because the OSGI is a thin modular layer on the JVM to some extent. I can not figure out why this design is a must.(Rhino problem?)

This Javascript language support in Eclipse is a especially interesting topic for me recently. I am also doing some EPLed ecmascript 5 experiments privately. The basic idea is using the Eclipse related technologies and JDK7 MLVM to refresh the status of "JavaScript on JVM"(new Rhino?). Is there someone in the community interesting this effort? Collaboration? 

Oh, a little away from the point:) In fact, one big reason for this article is that, I find no one know how to write a JavaScript Bundle and run it in the e4. Simon Kaegi said in the mail list that, they are busy doing tooling support, and "at the moment information is hard to come by other than the wiki page". As one of the most important features of e4, the missing of "Get Started" docs really blocks the passion of community. However, I think they just want to show the perfect achievement to the community when they are ready. 

After quickly sources reviewing yesterday, I find that it is possible to uncover the tip of the iceberg. Maybe there are many potential contributors to take part in the evolvement of the e4 language support.

Firstly, you can read basic infos from the e4/Javascript wiki page

I demonstrate how to code one co-located JavaScript bundles in a host OSGi bundle.(I doubt the usefulness of the semantics of the pure Javascript bundle.)

This kind of JS bundle consists of three key parts: "JavaScript-Bundle" header in, manifest.json(equivalent to the osgi, test.js(the name is arbitrary, however, you put the logic of bundle here). Some srceenshots seen as follow:

"JavaScript-Bundle" header in

manifest.json, note the name "Activator" should match with the constructor function in test.js(test0.js here is a bug-like script I found accidently, it seem a rhino bug. However, more dependencies cause more security problem...)

add "-console" arguments, and set the "auto-start" into true if you want to get the same screenshots below(orz, you can do it by hand)

the content of test.js(not use the rhino "print", you should borrow the "println" from Java), and we get the "Hello..." when start osgi(yeah, all wanted-to-be-started bundles will be started)

we get the "Goodbye..." when stop osgi(yeah,all started bundles will be stopped)

Congrats! You've got your first trusted Javascript bundles in e4!

Although this is a Helloworld Javascript bundle, I make sure that you can get more exciting things if you dig into the world of e4 language. 


Jin Mingjian said...

allow comments now?

Jin Mingjian said...


Axel Rauschmayer said...

Great stuff! What would be the next steps after this one? Writing servlets in JavaScript is quite useful (e.g. to communicate with browser-based JavaScript). Accessing other Java/JavaScript bundles is also important.

Jin Mingjian said...

Hi, Axel. I will check your question, although I am not a web-side man. This article is mainly targeted to inspire something. However, I think your problem is not hard.

Graham Jenson said...

Really cool post!!

kael said...

hello guy,

it's a really great post.

but in my experiences, i cant get a javascript bundle import a java package. the bundle doesnt init.

i putted:


in my json manifest, and:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Js
Bundle-SymbolicName: bundle.js
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
JavaScript-Bundle: scripts/manifest.json

in my

i tried too with a java bundle and it worked fine. is not that implemented in javascript framework yet?

kael said...

to how is trying, get this links:

so you can do. ;]