You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ronen Perez <ro...@gmail.com> on 2011/06/22 18:09:56 UTC

Setting pom properties from Maven Plugin for resource filtering

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?

Re: Setting pom properties from Maven Plugin for resource filtering

Posted by Marc Rohlfs <po...@googlemail.com>.
Hi Ronen,

take a look at the Properties Maven Plugin [1]. I don't have any 
experience with that plugin, because I haven't used it yet. But it looks 
like it should do exactly what You want to achieve with Your custom 
Maven plugin.
However, if it doesn't work out for You, You could at least take a look 
at the source code to see how it adds the properties to the project 
model. The Build Helper Maven Plugin [2] also sets some properties, You 
could check its sources, too.

One more point: I assume You checked that Your configuration of the 
Resources plugin works properly ...

Kind regards

    Marc

[1] http://mojo.codehaus.org/properties-maven-plugin
[2] http://mojo.codehaus.org/build-helper-maven-plugin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org