Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create ear in grails

grails supports creation of war. But is there any command to create an ear through grails?

like image 335
mahati Avatar asked Feb 02 '11 09:02

mahati


1 Answers

There's no direct support in Grails, but this Gant script will do the job. Simply added to scripts/ dir and invoked as grails ear.

Script originally posted by Graeme on mailing list

includeTargets << grailsScript("_GrailsWar")

target(ear: "Creates an EAR file from a Grails WAR") {
    war()   
    event("StatusUpdate", ["Building EAR file"])
    generateApplicationXml()
    def warDest = new File(warName).parentFile
    def earFile = "${projectTargetDir}/${contextRoot}.ear"
    ant.ear(destfile:earFile, appxml:appXml, update:true) {
        fileset(dir:warDest, includes:"*.war")
    }
    event("StatusFinal", ["Done creating EAR $earFile"])
}
target(defineContextRoot:"defines the context root") {
    contextRoot = "${grailsAppName}${grailsAppVersion ? '-'+grailsAppVersion : ''}" 
}
target(generateApplicationXml:"Generates an application.xml file") {
    depends(defineContextRoot)
    def warDest = new File(warName)
    appXml = "${projectTargetDir}/application.xml"
    new File(appXml).write """\
<?xml version="1.0" encoding="UTF-8"?> 
<application 
xmlns=http://java.sun.com/xml/ns/j2ee
       xmlns:xsi="http://www.w3.org/ 2001/XMLSchema-instance" 
       xsi:schemaLocation="http:// java.sun.com/xml/ns/j2ee 
           http://java.sun.com/xml/ns/j2ee/ application_1_4.xsd" 
       version="1.4"> 
<display-name>${grailsAppName}</display-name> 

<module> 
    <web> 
        <web-uri>${warDest.name}</web-uri> 
        <context-root>${contextRoot}</context-root> 
    </web> 
 </module> 

</application>  
"""
}

setDefaultTarget(ear)
like image 151
Burt Beckwith Avatar answered Oct 22 '22 20:10

Burt Beckwith