0

I need some help with replacing dynamic values. I am new to ant scripting and require some assistance.

I currently have one file on a server which will hold the properties that are specific for that server. i.e database connection details

ydkprefs.dbClassName=com.ibm.db2.jcc.DB2Driver
ydkprefs.dbType=DB2
ydkprefs.dbURL=jdbc:db2://localhost:50000/application
ydkprefs.dbschema=SCHEMA
ydkprefs.dbUsername=db2inst1

and then I have a template xml file with dynamic properties i.e.

 <Database Name=${dbName} className="${dbClassName}"
                dbType="${dbType}" folder=""
                jdbcURL="${dbURL}"
                schema="${dbschema}" user="${dbUsername}"/>

I have looked through a number of sites and I am none the wiser. The most promising information. The only thing that I have found that can work is to replace individual values which are stated within the ant script itself.

1 Answer 1

1

If you could change the property file and/or the template to make it so that the property names in the property file exactly match the placeholders you want to replace in the target file, then you could do it with

<copy file="template.xml" tofile="target.xml" encoding="UTF-8">
  <filterset begintoken="$${" endtoken="}" filtersfile="db.properties" />
</copy>

In order to produce well formed XML output you would also need to ensure that the property values are properly XML escaped where necessary, e.g. if you need to use an & character in a value then it needs to be &amp; in the properties file.

Sign up to request clarification or add additional context in comments.

1 Comment

I tip my hat to you sir. Thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.