tags:

views:

325

answers:

1

I'm using Spring and struts and have the following entry in 'C:/source/webapp/WebContent/META-INF/context.xml' with tokens like 'jdbc.username, jdbc.pwd, jdbc.server, jdbc.port and jdbc.databasename'.

   <Context cachingAllowed="false" useHttpOnly="true">
       <Resource name="jdbc/xxx" auth="Container" type="javax.sql.DataSource"
       factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
       maxActive="100" maxIdle="30" maxWait="10000"
       username="jdbc.username" password="jdbc.pwd"
       driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
       url="jdbc:sqlserver://jdbc.server:jdbc.port;databaseName=jdbc.databasename;"/>
   </Context>

I have a deployment directory - 'C:/deployment' and using ANT I build the deployment directory from 'C:/source'.

I use the following ANT replace task,

    <replace file="C:/deployment/META-INF/context.xml" replacefilterfile="C:/deployment/WEB-INF/classes/conf/int.properties" />

and replace jdbc.username,jdbc.pwd,jdbc.server,jdbc.databasename
with the values from the properties file.

Not sure how to achieve the following,

If i change the value of key 'jdbc.server' in the properties file, ANT replace task doesn't replace the value in 'C:/deployment/META-INF/context.xml'. If i delete the directory 'C:/deployment' and execute the target containing the replace task, then it changes the value of 'jdbc.server' in 'context.xml'.

I want to replace the changed value without deleting the directory 'C:/deployment'. How to do this. Is there any other ANT task available for this operation?

+1  A: 

Once you've replaced your keys, I assume they are no longer jdbc.username, jdbc.pwd, etc. Hence <replace> task cannot find them in your context.xml and, of course, cannot replace them.

What you need is a task that ties modification times of context.xml and int.properties. For this you can use ant-contrib's OutOfDate task.

Alexander Pogrebnyak
Thanks Alexander for letting me know ' <replace> task cannot find them in your context.xml and, of course, cannot replace them' -- before copying the context.xml, i deleted the already existing context.xml in the deployment directory thro' ANT delete, now the <replace> task replaces the value of keys as expected.
SyAu