Integrating Grails with an Existing Web Application

We have a large, bulky, but fairly stable web application written with Tapestry 4.1 that we want to gradually leave. To this end, we plan to develop some new features in Grails. Our customers should never know the difference, and if possible, no one internally, for example. installation services should also take care - ideally, the Grails application will be in the same WAR as the existing Tapestry code, only with the GrailsDispatcherServlet configured for a more specific path. It is also important that a minimal change to the monster build process for an existing application - re-creating the build system (currently Ant, switching to Maven) in Gant and Ivy is not an option. And it would be nice if we could work with exploded WARs for a live reboot during development.

Questions, then:

  • Is it possible?
  • If so, where to start?
  • If not, what is the best approach?
  • What do you need to keep track of?

Please note that we will not use GORM; all of our data comes from web services for which we already have a Java domain level and messaging levels.

+6
source share
2 answers

Good news: Yes, it is possible.

The bad news is a little hairy.

There are at least two ways:

  • As Dylan suggested, change the Grails build to host your existing application with some tweaking.
  • Create another Ant target that combines the existing WAR file with the WAR file created by Grails.

The first option, modifying the Grails assembly. The risk is that when a version of Grails is updated, a custom and modified build of Grails may not work at all, and you will not end here or there. Correcting this will require in-depth knowledge of how a structure generates an assembly. Since this is your initial encounter with the new structure, the learning curve may be too steep.

I would prefer the second, since you do not need to spoil the Grails assembly. You need to know how web.xml setup works. I assume that you already have this knowledge, since you already have your own Ant build. This is probably the path of least resistance.

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

The next step will cause the old application to work under Grails as a Java component called by Grails.

+2
source

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

You can use Ant and Maven (or Gradle) to create a Grails application, but since this is not a standard method, my experience is that a little tweaking may be required. I used Ant integration (which uses ivy for dependencies) to build and use Gradle to port Ant and change builds for special requirements.

The problem you may encounter is that the Gant scripts are core to Grails, and there are a lot of things going on in these scripts (depending on the plugins you use), which can cause problems with trying to merge the two assemblies together, as the scripts do not written to suit your use.

+1
source

Source: https://habr.com/ru/post/914928/


All Articles