mjn mjn - 2 months ago 34
Java Question

How can I use Maven project properties in izpack-maven-plugin install.xml?

Following http://maksim.sorokin.dk/it/2010/06/10/izpack-with-maven/ I wrote a Maven POM which creates an IzPack installer, using the izpack-maven-plugin.

However I found now way to pass plugin configuration parameters such as the artifact name and version to the install.xml file. Is there a way to pass these values from the POM to the plugin?

Example:

In the src/main/resources/install.xml:

<installation version="1.0">
<info>
<appname>MyApp</appname>
<appversion>1.0.0</appversion>
</info>
...


How can I use the Maven properties, project.name and project.version here, so it looks like:

<installation version="1.0">
<info>
<appname>${project.name}</appname>
<appversion>${project.version}</appversion>
</info>
...

Answer

Your maven-resources-plugin invocation can filter the resources involved using project properties defined in the pom itself, or better using a properties file. maven-resources-plugin usage

<build>
...
  <filters>
     <filter> [a filter property or properties file] </filter>
  </filters>
...
  <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4.2</version>
    ...
          <resources>
            <resource>
              <directory>src/main/resources</directory>
              <filtering>true</filtering>
            </resource>
          </resources>
     ...
  </plugin>
</build>

A filter property has this syntax in the pom:

<properties>
  <your.name>world</your.name>
</properties>

meaning "your.name" property has "world" value.

If you specify a properties file in src/main/resources:

your.name=world

and then indicate the filename in the <filter> element in the pom.