【问题标题】:create ear in grails在 grails 中创建耳朵
【发布时间】:2011-06-19 20:47:53
【问题描述】:

grails 支持创建战争。但是有没有通过grails创建耳朵的命令?

【问题讨论】:

    标签: jakarta-ee grails ear


    【解决方案1】:

    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)
    

    【讨论】:

    • 为什么这不是 grails 框架的一部分?
    • 也许这个脚本适用于早期版本的 grails,但对于 2.3.4,我收到一个错误,指出 warName 属性不存在。通过在脚本中将其定义为warName = "${basedir}/target/${grailsAppName}-${grailsAppVersion}.war" 来解决它。我从源代码中检查过,warName 属性似乎存在于 WarCreator.groovy 中(也可能存在于 _GrailsWar 脚本中),但由于某种原因对 Ear 脚本不可见。
    • 但是grails ear为开发环境生成,我需要为生产环境创建
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2011-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多