Thursday, December 19, 2013

Generate EAR File Using ANT Script

In this example, I will create an ANT script that generate EAR file. The only requirement is the ANT script tool that you can download from Apache. There are only 2 files to create, i.e. build.xml and application.xml.

First is to create META-INF folder. Under this folder create application.xml file with the following entries:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">
<application id="Application_ID">
    <display-name>MYEAR</display-name>
    <module>
        <web>
            <web-uri>dummy1.war</web-uri>
            <context-root>dummy1</context-root>
        </web>
    </module>
<module>
        <web>
            <web-uri>dummy2.war</web-uri>
            <context-root>dummy2</context-root>
        </web>
    </module>

</application>

Then create build.xml outside META-INF folder.

<?xml version="1.0" encoding="UTF-8"?>         
<project name="bankfusion" default="build">
<target name="build">
    <ear earfile="C:/folder/MyEar.ear"
         appxml="C:/folder/META-INF/application.xml">
      <fileset dir="C:/folder">
        <!-- WAR files should be copied in c:/folder -->
        <include name="*.war"/> 
      </fileset>
    </ear>
  </target>
</project>

This is the folder structure:

C:\folder
     + WEB-INF
          - application.xml
     + build.xml

To run the script, go to c:\folder then type ant.

i.e. 
c:\folder\ant

No comments:

Post a Comment