tags:

views:

1782

answers:

6

I was fortunate enough to be able to start fresh with Grails. However, many people have asked me how to add Groovy and/or Grails to a legacy Java/JSP web app. Do people have experience or recommendations on how to best include Groovy and Grails into a large legacy application?

+2  A: 

One thing I've seen done is to use Grails as the Admin interface for an Enterprise Java application. It isn't exactly what you asked because there is no integration. There was just a set of requirements that were easily partitioned and developed very quickly in Grails. In reality they are separate applications but use the same data.

Ed.T
+1  A: 

I'd start off by sharing the data model between the jsps and grails app (grails can run with plain Java classes and hibernate config, so if you are using hibernate already it shouldn't be hard to reuse the hibernate classes). Then I'd migrate each jsp/servlet as is to grails. If you are using spring already, it should make things easier since you can share the same application context.

Depending on how big the app is and other requirements, it might be better to rewrite the whole thing, specially if the legacy app doesn't use spring or hibernate.

Miguel Ping
A: 

I guess it depends on what is meant by "add grails/groovy" to an app - because grails is a full stack, and if by "add" you mean replace old with new, then it may be worth rewriting it.

Chii
A: 

I found this article that describes getting Groovlets and gsp's to work, specifying the web.xml updates and the jar files needed for the project.

http://www.ibm.com/developerworks/java/library/j-pg03155

I added the following jar files to my project and groovlets worked.

groovy-1.5.7.jar
asm-2.2.jar
antlr-2.7.6.jar

I don't have gsp's working yet.

+3  A: 

This IBM Developerworks article goes into detail about how to use Grails with your legacy database.

A tool that may help map legacy databases to grails domain objects is GRAG - the Grails Application Generator. It's a handy tool that helps generate the mapping classes for you.

A third option is to not use Grails for the gorm/domain layer. Instead, because it's works so well with Java, you can create services that call your existing legacy Java code for business logic and persistence.

I hope one of these approaches works for you.

Kevin Williams
A: 

Like others have said, Grails is a full stack, so adding Grails to an existing Java app might not be what you're looking for. Adding Java to an existing Grails app is trivial, however. And adding Groovy to an existing Java app might not be too hard either.

It depends a lot on the kind of Java app you're talking about. Grails is built on Spring MVC, Hibernate and similar standard Java technologies, so if your Java app is using all of that, it might easy to convert the app to Grails with some legacy Java code.

mcv
I already outlined in an answer how to include Groovlets in an existing Java/JSP project.