I have a conf file in a java app that contains an IP address parameter. I
want to be able to put in this parameter the local ip address automatically
at build time. I used maven resources-plugin as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>validate</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>/home/user/config</outputDirectory>
                <resources>
                    <resource>
                        <directory>config</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*.xml</include>
                            <include>**/*.properties</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>

Next, I've created a property that contains the parameter

<properties>
    <gateway.ip>${local.ip}</gateway.ip>
</properties>

Then, I've created a Maven plugin that gets the local ip address and sets
the above parameter:

final Properties props = mavenProject.getProperties();
props.put("local.ip", resultAddress.getHostAddress());

lastly, I define my custom plugin in the pom.xml:

<plugin>
    <groupId>com.applango</groupId>
    <artifactId>get-local-ip-plugin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <executions>
        <execution>
            <id>get-local-ip</id>
            <phase>validate</phase>
            <goals>
                <goal>get-local-ip</goal>
            </goals>
            <configuration>
                <localIp>${local.ip}</localIp>
            </configuration>
        </execution>
    </executions>
</plugin>

The problem is that this doesn't work and I get ${local.ip} in the resulting
file instead of xxx.xxx.xxx.xxx ip address.

Any suggestions?

Reply via email to