Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Grails with existing web application

We have a large, unwieldy but fairly stable web application written with Tapestry 4.1, which we're looking to gradually move off of. To that end we're looking at developing some new functionality in Grails instead. Our customers should never know the difference, and if possible, no one internally, e.g. in installation services, should have to care either -- ideally, the Grails app would be in the same WAR as the existing Tapestry code, just with GrailsDispatcherServlet configured for a more specific path. It's also crucial that there's the minimum of change to the monster build process for the existing application -- redoing the build system (currently Ant, transitioning to Maven) in Gant and Ivy isn't an option. And it would be nice if we could work with exploded WARs for live reloading during development.

Questions, then:

  • Is this possible?
  • If so, where do I start?
  • If not, what's the next best approach?
  • What do I need to watch out for?

Note by the way that we won't be using GORM; all our data comes from web services, which we already have Java domain and messaging layers for.

like image 741
David Moles Avatar asked May 04 '12 18:05

David Moles


2 Answers

Good news: Yes, it is possible.

Bad news: It's a bit hairy.

There is at least 2 way:

  1. As suggested by Dylan, modify the Grails build to accommodate your existing application, with some tweaking.
  2. Create another Ant target that combine existing WAR file with the WAR file produced by Grails.

The first option, modifying the Grails build. The risk is when Grails update version, the customized and tweaked Grails build may fail at all, and you will end neither here nor there. Fixing this will require deep knowledge about how the framework generate the build. As this is your initial encounter with a new framework, probably the learning curve will be too steep.

I would prefer the second, as you don't need to mess up with Grails build. You need to know the underlying, how the web.xml configuration works. I assume you already have this knowledge as you also already have your own Ant build. Probably this is the path of least resistance.

The downside of the second approach it will be difficult to have the exploded WAR during the development. But if you can separate the old application and the new application without the need to have them tested together during the development, you will have a good time when doing development in Grails using their lightweight development server.

The next step will bit by bit be making the old application able to run under Grails as Java component being invoked by Grails.

like image 71
Daniel Baktiar Avatar answered Nov 07 '22 00:11

Daniel Baktiar


You can edit the template for the web.xml to change the servlet mappings by running the grails install-templates command

You can use Ant & Maven (or Gradle) to build a Grails app but since is not the "standard" method my experience has been that some minor tweaking may be necessary. I have used the Ant integration (which uses ivy for dependencies) to build and used Gradle to wrap Ant and modify the build for special requirements.

The problem you may run into is that Gant scripts are core to Grails and many things happen in those scripts (depending on the plugins you use) that may cause issues with trying to merge the two builds together since the scripts are not written with your use case in mind.

like image 36
Dylan Bijnagte Avatar answered Nov 06 '22 23:11

Dylan Bijnagte