Please enter name
please enter valid email
please enter comment
Please enter correct code

Modularizing your Grails Application

Contributed by uttam on 1 Jan 2013

Modularizing your Grails application !!

Did you ever come across a requirement where your Domain classes had to be separated and then shared between two different applications. Achieving this in Grails is quite simple. However, we stepped on this process after initial development and hence moving in this direction was a bit painful, but if designed from day one it would be helpful and easier to achieve. Here are the steps:

Note at this time I was on grails 2.1.0

Create the plugin project

Simple command on your grails command

grails createPlugin Brandywine-DAL

What happens is that grails will create a plugin project for you. Now you can start creating your domain classes in this project. If you
happened to have have already a grails project with your domain classes as I did you first need move those domain files out of the
plugin project.

The plugin project is just an ordinary grails project with all the usual stuff of your grails-app, application.properities, test, web-app and the only new thing it adds is your BrandywineDALGrailsPlugin.groovy. You can do a lot of stuff in this plugin groovy file. Read more at grails creating plugin chapter.

Package the plugin

You just need to package your plugin

grails PackagePlugin

BTW, you need to be in your grails project to run this command as grails tries to find files being in it. What happens is that grails now has packaged your plugin as grails-brandywine-dal-0.1.zip

In my case I  limited to the domain classes but you can extend it to have your css files or resources files or controller or services.

Access your plugin in your application

Now you are ready to access your plugin right into your application by just the following command

grails install-plugin ../Brandywiner-DAL/grails-brandywine-dal-0.1.zip 

Thats it !!

Visit us at Neevtech.com to know more about our offerings.

2 Comments

  1. Appreciate the recommendation. Will try it out.

  2. congratulations all for the excellent text - very good

Leave a Comment

Security Code: