简体   繁体   中英

Read a particular value xml file and replace values in property file using ant

Suppose I have an xml file like abc.xml which contains

<datasource name="localmysql">
    <inline-jdbc jdbc-driver="com.mysql.jdbc.Driver"
                 jdbc-uri="url"
                 jdbc-username="username" jdbc-password="password"/>
</datasource>
<datasource name="localmysqlolap">
    <inline-jdbc jdbc-driver="com.mysql.jdbc.Driver"
                 jdbc-uri="url1"
                 jdbc-username="username1" jdbc-password="password1"/>
</datasource>
<datasource name="localmysqltenant">
    <inline-jdbc jdbc-driver="com.mysql.jdbc.Driver"
                 jdbc-uri="url2"
                 jdbc-username="username2" jdbc-password="password2"/>
</datasource>

Now I want to read the values of jdbc-uri, jdbc-username, jdbc-password in node

datasource name="localmysql" and change the values of a property file which also contains jdbc-uri, jdbc-username, jdbc-password as keys. Is there a way to do it using ant

You can use ANT replace task and replace each value. In this case you will need to know old/new properties values.

I used property regex task from ant-contrib

Please remember, that properties in ANT are immutable and can't be modified/updated

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM