Ken Alton
Ken Alton

Reputation: 734

Maven Properties List

Despite the title, I'm not looking for a list of properties to use with Maven.

I wish to set up a profile that contains a list of items, in this case a server list. A local dev profile will have just a single server whereas for testing there could be one, two or more.

How can I write a list of items that are basically 'the same thing'?

<profile>
    <id>DEV_COMMON</id>
    <properties>
        <kafka.config.retries>3</kafka.config.retries>
        <kafka.brokers> <!-- the following causes Maven error -->
            <server>
                <host>hostname1</host>
                <port>1234</port>
            </server>
            <server>
                <host>secondhostname</host>
                <port>5678</port>
            </server>
            <server>
                <host>hostnameNumber3</host>
                <port>9101</port>
            </server>
        </kafka.brokers>
    </properties>
</profile>

The profile above produces the error:

TEXT must be immediately followed by END_TAG and not START_TAG

Assistance greatly appreciated. KA.

Upvotes: 1

Views: 610

Answers (1)

Little Santi
Little Santi

Reputation: 8793

The problem is that the properties in Maven (AFAIK) do not allow repeatibility of values, because each property can be accessed just by name:

${test.server}

... So you wouldn't be able to access other properties than the first. That's why Maven does not even allow sub-nodes within the properties node.

As a lesser evil, I'd give these properties an unique name:

<properties>
    <kafka.broker.server1.host>hostname1</kafka.broker.server1.host>
    <kafka.broker.server1.port>1234</kafka.broker.server1.port>
    <kafka.broker.server2.host>hostname2</kafka.broker.server2.host>
    <kafka.broker.server2.port>1235</kafka.broker.server2.port>
</properties>

Upvotes: 1

Related Questions