I'm currently facing a problem while trying to write an ant task that looks
up for some xml elements and adds a prefix in front of that specific
element.

I have to run this script twice since I have two files to change which have
pretty much the same structure. What it basically does is:

1. unzip the 1st .ear file to /temp/ear
2. unzip the included .war file to /temp/ear/war
3. change the nodes
4. zip the war file
5. zip the ear file
6. run the same procedure for the 2nd .ear file

All that tasks are controlled by the "Task" target.



Here's some of my code:

<?xml version="1.0"?>

<project name="Evaluation" default="Tasks" basedir=".">

<record name="log.txt" action="start" append="false"/>

<property name="src" value="."/>
<property name="build" value="build"/>
<property name="earWorking" value="temp/ear"/>
<property name="warWorking" value="${earWorking}/war"/>
<property name="akteEarFile" value="eAkteEAR-20081001-0720.ear"/>
<property name="pkEarFile" value="ePKEAR-20081001-1140.ear"/>
<property name="pkWarFile" value="ePKPortlets.war"/>
<property name="akteWarFile" value="eAktePortlets.war"/>
<property name="registerEAR" value="temp/ear/registerEPKEAR.xml"/>



<taskdef name="xmltask"
classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

    <!--EAR-File unpacking-->
     <target name="PKearUnzip" description="Unzips the EAR archive">
          <unzip src="${pkEarFile}" dest="${earWorking}"/>
     </target>

     <!--WAR-File unpacking-->
     <target name="PKwarUnzip" depends="PKearUnzip" description="Unzips the
WAR archive">
        <unzip src="${earWorking}/${pkWarFile}" dest="${warWorking}"/>
     </target>


    ...


    <!-- Changing the Nodes-->
<target name="registerEPKEAR.xml" depends="ApplicationXML"
description="registerEPKEAR.xml">


    <xmltask source="${registerEAR}">

        <copy path="/request/portal/web-app/display-name/text()"
property="prop1"/>
        <copy path="/request/portal/web-app/portlet-app/@name"
attrvalue="true" property="prop2"/>
        <copy path="/request/portal/web-app/portlet-app/portlet[1]/@name"
attrvalue="true" property="prop3"/>
        <copy path="/request/portal/web-app/portlet-app/portlet[2]/@name"
attrvalue="true" property="prop4"/>
        <copy path="/request/portal/web-app/portlet-app/portlet[3]/@name"
attrvalue="true" property="prop5"/>
        <copy path="/request/portal/web-app/portlet-app/portlet[4]/@name"
attrvalue="true" property="prop6"/>
                <uncomment path="/request/portal/web-app/url[3]"/>

    </xmltask>

    <replace file="${registerEAR}" token="&lt;context-root&gt;/"
value="&lt;context-root&gt;/Schulung_" summary="true"/>
    <echo message="display-name: ${prop1}"/>
    <echo message="ID: ${prop2}"/>
    <echo message="ID: ${prop3}"/>
    <echo message="ID: ${prop4}"/>
    <echo message="ID: ${prop5}"/>
    <echo message="ID: ${prop6}"/>

    <xmltask dest="${registerEPKEAR}">
        <replace path="/request/portal/web-app/display-name/text()"
withText="Schulung_${prop1}"/>
        <attr path="/request/portal/web-app/portlet-app" attr="name"
value="Schulung_${prop2}"/>
        <replace path="/request/portal/web-app/portlet-app/portlet[1]/@name"
withText="Schulung_${prop3}"/>
        <replace path="/request/portal/web-app/portlet-app/portlet[2]/@name"
withText="Schulung_${prop4}"/>
        <replace path="/request/portal/web-app/portlet-app/portlet[3]/@name"
withText="Schulung_${prop5}"/>
        <replace path="/request/portal/web-app/portlet-app/portlet[4]/@name"
withText="Schulung_${prop6}"/>

    </xmltask>

        <var name="prop1" value="" unset="true" />
        <var name="prop2" value="" unset="true" />
        <var name="prop3" value="" unset="true" />
        <var name="prop4" value="" unset="true" />
        <var name="prop5" value="" unset="true" />
        <var name="prop6" value="" unset="true" />
        <var name="registerEAR" value="temp/ear/registerEAkteEAR.xml"
unset="false" />


    </target>

    <target name="Tasks">
        <antcall target="PKwarUnzip"/>
        <antcall target="PKZip"/>

        <antcall target="EAwarEntpacken" inheritAll="true" />
        <antcall target="EAPacken" inheritAll="true"/>

    </target>


After the 1st run the property registerXML has to change to another filename
since the name in the 2nd EAR file I am working with is a different one. I
tried something but without any success, ant always looks up for the "old"
filename without changing the property to the new filename and I'm getting:

registerEPKEAR.xml:
  [xmltask] java.io.FileNotFoundException: C:\Documents and
Settings\Administrator\workspace\ANT\temp\ear\registerEPKEAR.xml (The system
cannot find the file specified)

BUILD FAILED
C:\Documents and Settings\Administrator\workspace\ANT\build.xml:340: The
following error occurred while executing this line:
C:\Documents and Settings\Administrator\workspace\ANT\build.xml:67:
C:\Documents and
Settings\Administrator\workspace\ANT\temp\ear\registerEPKEAR.xml (The system
cannot find the file specified)

Line 67 is the term "<xmltask source="${registerEAR}">"

I'm out of ideas now. Any help is appreciated.

Reply via email to