Integrating Grails with existing web application
Asked Answered
V

2

6

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.

Vasyuta answered 4/5, 2012 at 18:51 Comment(6)
Do you use hibernate for persisting data or do you use something else ?Balaam
just a few thoughts - how about creating the grails app separately, and then bundling the grails app's war with the original app's war, as a .ear file? That way, you can keep your original build, keep grails working the way it was meant to, and just add the extra step at the end to build the .ear file. The big questions would be what the level of integration is between the two, what the integration points are, and how to pull off the appropriate url re-writing to make it appear seamless.Stallings
Outside of the fact that you would be using Java instead of Groovy it sounds like you may be better served by doing Spring MVC (a major component of Grails).Kennethkennett
@Balaam The data is on the other side of a web service, which as it happens does use Hibernate for database access, but also works with other, more distant web services and, for historical reasons, flat files (which are shared with legacy C apps).Vasyuta
@Stallings Interesting thought. I'd prefer to avoid the build/distribution turmoil (in buildfiles and in office politics) that would result from changing the way we distribute the original app, but that might end up being the way we have to go.Vasyuta
@DylanBijnagte You might be right, but (1) that would open up a big argument about Tiles vs. Velocity vs. FreeMarker and (2) Grails (being in use by some other teams) already has internal political acceptance, even if the higher-ups who approved it don't actually know what it is. Personally, I'm also not convinced that (apart from the integration issues) Spring MVC out of the box would be as productive as Grails.Vasyuta
K
2

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.

Kashakashden answered 16/5, 2012 at 6:24 Comment(0)
K
1

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.

Kennethkennett answered 15/5, 2012 at 3:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.