Announcement Announcement Module
Collapse
No announcement yet.
Grails : Creating two separate war file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grails : Creating two separate war file

    Is it possible in grails, to generate two separate war files, while creating build. or is it possible to selectively create war file, with only selected controllers files in it?

    I need some means to group certain controllers to a war file and other to another war.

  • #2
    Yes, this is possible. The WAR process triggers an event just before the WAR file is created that you can use to do what you want. Create a file scripts/_Events.groovy in your project and add the following code to it:
    Code:
    eventCreateWarStart = { name, stagingDir ->
        // Remove the controllers we don't want in the WAR
        new File(stagingDir, "WEB-INF/classes").eachFileRecurse { f ->
            if (f.name?.startsWith("MyController")) {
                f.delete()
            }
        }
    }
    Whatever is left in the staging directory once you've finished gets packaged into the WAR.

    Hope that helps.

    Comment


    • #3
      Thanks.. That was very close... but instead of deleting matched files, i need to create a separate war file for them. Is it possible to create separate war files through code..? Please advice..

      Comment


      • #4
        Yes. You can call ant.jar() or ant.war() from your event handler:
        Code:
        eventCreateWarStart = { name, stagingDir ->
            ...
            // Create another WAR file
            ant.war(destfile: "target/my-other.war") {
                classes {
                    include dir: grailsSettings.classesDir.path, name: "**/*OtherController.class"
                }
            }
        }
        I haven't tested the above, but basically you can invoke any Ant task as if it were a method. The named arguments match the XML attributes of the task element. 'classes' corresponds to a nested element.

        For more information, see chapter 4 of the user guide. the 'grailsSettings' variable is an instance of BuildSettings - chapter 4 shows some of the available properties.

        Comment

        Working...
        X