views:

653

answers:

4

I want to move a legacy java web application (J2EE) to a scripting language -- any scripting language -- in order to improve programming efficiency.

What is the easiest way to do this? Are there any automated tools that can convert the bulk of the business logic?

+6  A: 

Using an automated tool to "port" the web application will almost certainly guarantee that future programming efficiency will be minimised -- not improved.

A good scripting language can help programming efficiency when used by good programmers who understand good coding practices in that language. Automated tools are usually not designed to output code that is elegent or well-written, only code that works.

You'll only get an improvement in programming efficiency after you've put in the effort to re-implement the web app -- which, due to the time required for the reimplementation, may or may not result in an improvement overall.

TimB
+7  A: 

If you already have a large amount of business logic implemented in Java, then I see two possibilities for you.

The first is to use a high level language that runs within the JVM and has a web framework, such as Groovy/Grails or JRuby and Rails. This allows you to directly leverage all of the business logic you've implemented in Java without having to re-architect the entire site. You should be able to take advantage of the framework's improved productivity with respect to the web development and still leverage your existing business logic.

An alternative approach is to turn your business logic layer into a set of services available over a standard RPC mechanisim - REST, SOAP, XML-RPC or some other simple XML (YAML or JSON) over HTTP protocol (see also DWR) so that the front end can make these RPC calls to your business logic.

The first approach, using a high level language on the JVM is probably less re-architecture than the second.

If your goal is a complete migration off of Java, then either of these approaches allow you to do so in smaller steps - you may find that this kind of hybrid is better than whole sale deprecation - the JVM has a lot of libraries and integrates well into a lot of other systems.

Kyle Burton
Hey, don't forget Jython (Python running under the Java Virtual Machine)! You can run the Django framework under Jython, and probably others too that I don't know about.
Dan
+8  A: 

Here's what you have to do.

First, be sure you can walk before you run. Build something simple, possibly tangentially related to your main project.

DO NOT build a piece of the final project and hope it will "evolve" into the final project. This never works out well. Why? You'll make dumb mistakes. But you can't delete or rework them because you're supposed to evolve that mistake into the final project.

Next, pick a a framework. What? Second? Yes. Second. Until you actually do something with some scripting languages and frameworks, you have no real useful concept of what you're doing. Once you've built something, you now have an informed opinion.

"Wait," you say. "To do step 1 I had to pick a framework." True. Step 1, however, contains decisions you're allowed to revoke. Pick the wrong framework for step 1 has no long-term bad effects. It was just learning.

Third, with your strategic framework, and some experience, break down your existing site into pieces you can build with your new framework. Prioritize those pieces from most important to least important.

DO NOT plan the entire conversion as one massive project. It never works. It makes a big job more complex than necessary.

We'll use Django as the example framework. You'll have templates, view functions, model definitions, URL mapping and other details.

For each build, do the following:

  1. Convert your existing model to a Django model. This won't ever fit your legacy SQL. You'll have to rethink your model, fix old mistakes, correct old bugs that you've always wanted to correct.

  2. Write unit tests.

  3. Build a conversion utility to export old data and import into the new model.

  4. Build Django admin pages to touch and feel the new data.

  5. Pick representative pages and rework them into the appropriate templates. You might make use of some legacy JSP pages. However, don't waste too much time with this. Use the HTML to create Django templates.

  6. Plan your URL's and view functions. Sometimes, these view functions will leverage legacy action classes. Don't "convert". Rewrite from scratch. Use your new language and framework.

The only thing that's worth preserving is the data and the operational concept. Don't try to preserve or convert the code. It's misleading. You might convert unittests from JUnit to Python unittest.


I gave this advice a few months ago. I had to do some coaching and review during the processing. The revised site is up and running. No conversion from the old technology; they did the suggested rewrite from scratch. Developer happy. Site works well.

S.Lott
+1 "DO NOT plan the entire conversion as one massive project. It never works. It makes a big job more complex than necessary."You need a strategy to move key parts over, meaning at one stage, you will have some type of hybrid.
gregturn
Some folks to and some folks don't. You can convert in pieces, but not go live until everything is converted. This can get costly. My preference is to have a hybrid for a while. In some cases, the low-priority stuff doesn't need to be converted. It can be dropped.
S.Lott
+1  A: 

A lot of the recommendations being given here are assuming you -- and just you -- are doing a full rewrite of the application. This is probably not the case, and it changes the answer quite a bit

If you've already got J2EE kicking around, the correct answer is Grails. It simply is: you probably already have Hibernate and Spring kicking around, and you're going to want the ability to flip back and forth between your old code and your new with a minimum amount of pain. That's exactly Groovy's forte, and it is even smoother than JRuby in this regards.

Also, if you've already got a J2EE app kicking around, you've already got Java developers kicking around. In that case, learning Groovy is like falling off a ladder -- literally. With the exception of anonymous inner classes, Groovy is a pure superset of Java, which means that you can write Java code, call it Groovy, and be done with it. As you become increasingly comfortable with the nicities of Groovy, you can integrate them into your Java-ish Groovy code. Before too long, you'll be writing very Groovy code, and not even really have realized the transition.

Robert Fischer