Ant: Is it possible to get a specific property from an xml file?

I use ant to install servers for testing. In the properties file, I have a list of parameters for the database. The problem is that I need to change 5-6 parameters when changing the database. Most of them depend on the database name. Therefore, I thought that I was creating an xml file with all the various databases that we use, and just enter a name in the properties file. Then, when the build file is running, it gets the correct properties for the database in use. I created the xml file as follows:

<databases>
<database>
    <server>mssql_1</server>
    <port>1433</port>
    <sid_instance>foobar</sid_instance>
    <path></path>
    <hostuser>sa</hostuser>
    <hostpwd>password</hostpwd>
    </database>
<database>
    <server>oracle_1</server>
    <port>1521</port>
    <sid_instance>foobar</sid_instance>
    <path>C:\\oracle\\oradata\\foobar</path>
    <hostuser>system</hostuser>
    <hostpwd>password</hostpwd>
</database>
</databases>

I call the file in the assembly file with

<xmlproperty file="databases.xml"  />

So, when the properties file indicates that "mssql_1" will be used, I want the appropriate properties to load.

, , : "1433, 1521",

<echo message="${databases.database.port}">

, . , .

+3
1

. <xmlproperty> XML , . , .

, , <property> file . :

database.mssql.properties

server=mssql_1
port=1433
sid_instance=foobar
path=
hostuser=sa
hostpwd=password

database.oracle.properties

server=oracle_1
port=1521
sid_instance=foobar
path=C:/oracle/oradata/foobar
hostuser=ssytem
hostpwd=password

build.xml :

<property name="database"  value="mssql"/>   <!-- Default database -->
<property name="database.file   value="database.${database}.properties"/>

<fail message="No such database file &quot;${database.file}&quot;">
    <condition>
        <not>
            <available file="${database.file} type="file"/>
        </not>
    </condition>
 </fail>

<property file="${database.file}"/>

- Ant, -D :

$ ant -Ddatabase=oracle

database build.xml Oracle. , (MS SQL one).

, :

<property file="build.properties"> <!-- Contains database name -->
<property name="database.file"   value="database.${database}.properties"/>
+3

All Articles