Search code examples
mavenbuildantmaven-antrun-pluginmaven-ant-tasks

Issue with replacing multiple lines in xml during maven build


I need to replace mutliple lines in .wsdd file in war generated after my maven build.

I am using antrun-maven-plugin and ant's replace task for this purpose.

Below is the snippet from pom.xml:

<plugin>
   <groupId>com.github.odavid.maven.plugins</groupId>
   <artifactId>antrun-maven-plugin</artifactId>
   <executions>
    <execution>
     <phase>package</phase>
      <configuration>
       <target>
        <ant antfile="replace.xml">
         <target name="replace-config"/>    
        </ant>
       </target>
      </configuration>
     <goals>
      <goal>run</goal>
     </goals>
    </execution>
   </executions></plugin>

Here the replace.xml contains ant target to actually replace the multiline token and updating final war with replaced .wsdd file, below is part where we replace the multiline token in .wsdd file.

<target name ="replace-config">
<echo>********** Replacing tokens in server-config.wsdd file *************</echo>
<replace dir="${basedir}/target/as_gen/WEB-INF/" >
    <include name="server-config.wsdd"/>
    <replacetoken><![CDATA[<requestFlow>      
                             <handler type="java:org.apache.axis.handlers.JWSHandler">        
                                 <parameter name="scope" value="session"/>      
                             </handler>      
                             <handler type="java:org.apache.axis.handlers.JWSHandler">        
                                <parameter name="scope" value="request"/>        
                                <parameter name="extension" value=".jwr"/>      
                             </handler>    
                    </requestFlow>]]></replacetoken>
    <replacevalue><![CDATA[<requestFlow>      
                               <handler type="java:com.as.webservices.TS9TicketTokenSender">        
                                 <parameter name="scope" value="session"/>      
                               </handler>      
                                <handler name="_wss4j_as_receiver_handler" type="java:com.as.security.asWSSReceiverHandler">        
                                    <parameter name="action" value="NoSecurity"/>      
                                </handler>    
                                <handler type="java:com.cm.ChangeHandler"/>
                                <handler type="java:com.cm.WSLoggingHandler"/>
                         </requestFlow>
                         <responseFlow>      
                         <handler type="java:com.as.webservices.TS9TicketTokenSender"/>      
                         <handler name="_wss4j_as_sender_handler" type="java:com.as.security.asWSSSenderHandler">        
                            <parameter name="signatureKeyIdentifier" value="IssuerSerial"/>        
                         <parameter name="encryptionKeyIdentifier" value="IssuerSerial"/>        
                         <parameter name="action" value="NoSecurity"/>      
                         </handler>    
                         <handler type="java:com.cm.WSLoggingHandler"/>
                        </responseFlow>  
   ]]></replacevalue>
</replace>             

Now this gives correct results when run on unix machine, and token is successfully replaced by replace value but somehow the replacement does not take place on my windows machine.

Kindly help with issue identification and alternate method to do so. Thanks.


Solution

  • I was able to do this using ant's replaceregexp task. identified the first content between <requestFlow>....</requestFlow> in match attribute and added the replaced value in replace attribute of replaceregexp task