2011-02-02 19 views

Trả lời

9

Không có hỗ trợ trực tiếp trong Grails, nhưng tập lệnh Gant này sẽ thực hiện công việc. Chỉ cần thêm vào scripts/ dir và được gọi là grails ear.

Script Nguyên văn bởi 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) 
+0

Bất kỳ lý do nào tại sao đây không phải là một phần của khung grails? – kaskelotti

+3

Có lẽ tập lệnh này đã hoạt động đối với các phiên bản trước của grails, nhưng đối với '2.3.4', tôi nhận được thông báo lỗi rằng thuộc tính warName không tồn tại. Giải quyết nó bằng cách định nghĩa nó trong kịch bản là 'warName =" $ {basedir}/target/$ {grailsAppName} - $ {grailsAppVersion} .war "'. Tôi đã kiểm tra từ các nguồn và có vẻ như thuộc tính warName hiện diện trong WarCreator.groovy (và cũng có thể trong tập lệnh _GrailsWar), nhưng không hiển thị với kịch bản lệnh Ear vì một lý do nào đó. – kaskelotti

+0

nhưng tai grails tạo ra cho môi trường phát triển, tôi cần tạo ra môi trường sản xuất – sirdaiz

2

Đây là một câu trả lời rất muộn, nhưng ngày nay các plugin grails maven là khá tốt. Vì vậy, bạn chỉ có thể xây dựng một tai ra khỏi cuộc chiến được sản xuất bởi các plugin mils grails.