用grails创造耳朵

时间:2011-02-02 09:56:57

标签: java-ee grails ear

grails支持创造战争。但有没有命令通过grails创建一个耳朵?

2 个答案:

答案 0 :(得分:9)

Grails没有直接的支持,但是这个Gant脚本可以完成这项工作。只需添加到scripts/目录并调用grails ear

最初由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)

答案 1 :(得分:2)

这是一个非常晚的答案,但现在grails maven插件非常好。所以你可以在grails maven插件产生的战争中建立一个耳朵。