Search code examples
javajenkinsantearibm-rad

How to create application.xml in code when generate EAR file?


IBM RAD allow to export EAR from IBM portal projects. I am writing a project to auto create ear files. As you know, an EAR file include WAR file and the folder META-INF (that include file application.xml). But how can I create file application.xml in code ?

For example, I want to create a below application.xml in my build.xml file, how to do that :

<?xml version="1.0" encoding="UTF-8"?>
<application id="Application_ID" version="6" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd">
 <display-name>HTDKTTEAR</display-name>
 <module id="Module_1463815058194">
    <web>
        <web-uri>HTDKTT.war</web-uri>
        <context-root>HTDKTT</context-root>
    </web>
 </module> 
 </application> 

My build.xml file:

<target name="generateEar" depends="generateWar">
        <mkdir dir="./earbin/META-INF"/>
        <manifest
            file="./earbin/META-INF/MANIFEST.MF"
            mode="update">
            <attribute name="Built-By" value="Jenkins CI"/>
            <attribute name="Implementation-Version" value="#${env.BUILD_NUMBER} - r${env.SVN_REVISION} - ${env.BUILD_ID}"/> 
            <attribute name="Implementation-Title" value="${env.JOB_NAME}"/>
            <attribute name="Built-Date" value="${TODAY}"/>
        </manifest>

        <move file="BUILD2TEST.war" todir="./earbin" />
        **<!-- How to create application.xml ? if it not available /> -->**
        <jar destfile="${ear}">
            <fileset dir="./earbin" />
        </jar>
    </target>

Solution

  • Expanding on my comment of keeping a template of application.xml. For example i kept DISPLAY_NAME as a token that will be replaced at runtime.

    <?xml version="1.0" encoding="UTF-8"?>
    <application id="Application_ID" version="6" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd">
     <display-name>DISPLAY_NAME</display-name>
     <module id="Module_1463815058194">
        <web>
            <web-uri>HTDKTT.war</web-uri>
            <context-root>HTDKTT</context-root>
        </web>
     </module> 
     </application>
    

    Following replace task will replace DISPLAY_NAME token with "My Enterprise App" in above application.xml

        <replace casesensitive="true" file="application.xml">
            <replacetoken>DISPLAY_NAME</replacetoken>
            <replacevalue>My Enterprise App</replacevalue>
        </replace>
    

    Similarly you can keep other values as tokens in your template application.xml and replace them at runtime with actual values.

    For more details please see : ANT Replace Task

    Hope this helps