Developers, Developers, Developers! Maksim Sorokin IT Blog

10Jun/10Off

IzPack with Maven

What does Maven? Maven builds a project. What does IzPack? IzPack builds an installer. Naturally, one would like to use Maven to control IzPack. Here is an example of a simple application which uses Maven and IzPack to create an installer for an application.

We start by creating a pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>test</groupId>
  <artifactId>test18</artifactId>
  <name>Test IzPack and maven</name>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
    <staging.dir>${project.build.directory}\staging</staging.dir>
    <izpack.standalone.compiler.version>4.3.2</izpack.standalone.compiler.version>
  </properties>

  <build>
    <plugins>
      <!-- Used to configure IzPack installer -->
      <plugin>
        <groupId>org.codehaus.izpack</groupId>
        <artifactId>izpack-maven-plugin</artifactId>
        <version>1.0-alpha-5</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>izpack</goal>
            </goals>
            <configuration>
              <izpackBasedir>${staging.dir}</izpackBasedir>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.izpack</groupId>
            <artifactId>izpack-standalone-compiler</artifactId>
            <version>${izpack.standalone.compiler.version}</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.2</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <encoding>UTF-8</encoding>
              <outputDirectory>${staging.dir}</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/resources</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Provided Maven packaging is pom since we don't want to produce any application jars. IzPack will create a executable jar file by itself.
And we are using two plugings. One is Maven IzPack plugin. And another one is used to copy installation files to the "staging" directory. Staging directory it is where all needed resources are copied. Executable jar will be created from it afterwards.

And then in the src/main/resources we create a install.xml configuration file which configures our installation:

<?xml version="1.0" encoding="UTF-8"?>

<installation version="1.0">

  <info>
    <appname>Test Installer</appname>
    <appversion>1</appversion>
    <uninstaller write="no" />
    <javaversion>1.6</javaversion>

    <pack200 />
  </info>

  <guiprefs resizable="no" width="480" height="360">
    <laf name="looks">
      <param name="variant" value="windows" />
      <os family="windows" />
    </laf>
  </guiprefs>

  <locale>
    <langpack iso3="eng" />
  </locale>

  <panels>
    <panel classname="HelloPanel" />
    <panel classname="SimpleFinishPanel" />
  </panels>

  <packs>
    <pack name="main" required="yes">
      <description>Test Installation</description>
    </pack>
  </packs>

</installation>

All the detailed about this install.xml configuration file can be found on IzPack documentation page.

And now we are ready to go. Run mvn install and in target folder you will find an installer! It will consist of two panels -- Hello Panel and Finish Panel. Nothing fancy. But you have to start somewhere!

Comments (7) Trackbacks (3)
  1. Great you hit the spot for me :) Keep the posts comming :)

  2. How do you add shortcuts?

  3. Hi, Dan! Thanks for your comment.

    Take a look to a Desktop Shortcuts section in official IzPack documentation

  4. Just FYI, the install.xml has to be at src/main/izpack, NOT src/main/resources. Not sure what version this is of.

  5. My previous comment was wrong, but I believe there is a typo in the above POM: the section has to be inside the level, not the :

    org.codehaus.izpack
    izpack-maven-plugin
    1.0-alpha-5

    package

    izpack

    ${staging.dir}

  6. KP, install.xml is in src/main/resources because we do some “staging” before running IzPack compiler. That is, replace ${…} inside install resources and sometimes do additional stuff.

    Actually, everything should be fine with sections and nestings. This is copy-paste from real application.

  7. If I have some of install.xml files at different directories and resource downloading is not needed, what should I do?


Leave a comment