Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I port a legacy Java/J2EE website to a modern scripting language (PHP,Python/Django, etc)?

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?

like image 464
user26294 Avatar asked Nov 29 '22 05:11

user26294


2 Answers

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.

like image 89
S.Lott Avatar answered Dec 05 '22 04:12

S.Lott


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.

like image 21
Kyle Burton Avatar answered Dec 05 '22 04:12

Kyle Burton