Project Phobos — A proof of concept, for now
I was excited by what I’d heard and primed by Project Phobos — A Scripting Framework for the Java Platform, so I decided to take a closer look. In short, Phobos is a web framework that integrates scripting languages such as JavaScript and Ruby with Java on the server, with the added benefit of Dojo and jMaki libraries on the client. See the article for more.
Integrating scripting languages had been debated in the Java world for a long time. Sun, well aware of their potential and popularity, began promoting the JVM as a platform for many different languages. Java 6 added scripting-language integration, exemplified by its integration with JavaScript.
Phobos builds on JavaScript integration. It implements a full web MVC framework in JavaScript on top of the Servlet API. You can write the server side of your application entirely in JavaScript or write parts such as the view and controller in JavaScript and the model in Java. Focusing solely on JavaScript would be misleading, since Phobos talks about integrating any JSR-223-compatible engine. See Scripting Engines.
Most of Phobos is written in JavaScript, and its developers recommend it for your application too. You can call any API that’s part of Java from JavaScript without difficulty. Integrating PHP, for example, would be trickier because you’d need to call it directly from JavaScript, the language in which Phobos is implemented.
Here’s a piece of code from a Phobos application to show what I mean.
library.common.define(controller, "form", function() {
this.Form = function() {
this.update = function() {
// ... code to update the form goes here ...
}
}
});That’s the controller. Phobos calls its update method for a request to /form/update.
The code looks fine until you imagine writing several thousand more lines like it. I tried NetBeans 5.5 with Phobos support, and it doesn’t do much. Of the things developers spend time on, it basically handles only debugging. I see two main problems with Phobos.
- Weak IDE support, which will hopefully improve with NetBeans 6.0
- JavaScript
Some people are delighted by the tremendous efficiency of scripting languages. Frankly, I turn up my nose at them. The fact that JavaScript doesn’t support OOP puts me off, and the code above makes me break into a cold sweat. In JavaScript, about all you can speak of is support for inheritance. You can forget about a standard way to organize objects into structures such as packages or to encapsulate variables or functions.
These are probably problems with the current implementation more than with Phobos itself. It’s worth recognizing that the team pulled off a proof of concept for integrating Java with scripting technologies. In terms of functionality, Phobos currently gives you nothing established Java web frameworks didn’t already offer, and those come with strong IDE support.
My conclusion is that the current version of Phobos is fit only as a proof of concept. An exception might be if your developers know only JavaScript. They might find it easier to adapt to Phobos than to move entirely to Java, JSF and JSP.
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio