We need you!

Icon

The IzPack documentation needs work, and you are invited to edit it!

Skip to end of metadata
Go to start of metadata

Preparation

The Laying out your project files for a Maven build page describes the overall layout of a maven project.

Compiling Using Maven

To compile IzPack using Maven, use the izpack-maven-plugin. There is good documentation at the izpack-maven-plugin page, but this page will describe how to use the most recent IzPack plugin.

Custom IzPack panels are supported and are discussed in the "Using Custom Panels" section.

Creating the Maven installer project for IzPack

Create a separate Maven project that will produce your izPack installer. You can refer to the IzPack Maven Plugin Reference section for details on the plug-in and the meaning of the configuration settings.

The basic strategy is as follows:

  1. Configure the Maven pom to create a "staging" area that will contain our izPack descriptor and all of our installer resources, including the jars that we want to include in our installer. 
    1. Use the Maven maven-antrun-plugin to copy our izPack descriptor file and resources into this "staging" area. 
    2. Use the maven-dependency-plugin to copy the jar with our custom panels, and any other jar dependencies that we want in our installer. Two different "executions" of the maven-dependency-plugin may be required; one to copy our application jars into one location, and if there are custom panels, another to copy the custom panel jars into a separate location.
  2. We'll then configure the izpack-maven-plugin to point it to our staging area and our installer descriptor.
Create Some Helpful Properties
The staging area location will be referenced a few times in the pom, so let's configure it as a <property> to make things clearer.  Also configure the izPack version.
Put these in the <properties> element under the root element of your pom file:

Notes:

  • ${project.build.directory} references the compilation ./target/ directory of your module
  • Properties from your Maven project can be directly references in the install.xml using the property name enclosed in '@{' and '}' , for example:
    <jar src="@{izpack.staging}/lib/appcore.jar"/>
    This only applies to properties defined in the compiling project.
Add Your Dependencies
  • Add the dependency that contains your actual Java application to be installed.
  • If custom panels are used, add the dependency that contains your custom panel, 

 

Configure the maven-antrun-plugin

Use the maven-antrun-plugin to copy the installer descriptor and installer resources (images, text files, etc.) into the "staging" area.

Put the installer descriptor and resources underneath src/izpack in your module. In the pom's <build> section, configure the maven-antrun-plugin to copy this entire directory to the staging area:

Configure the maven-dependency-plugin

Configure the maven-depenency-plugin to copy the application's jars.

If there are custom panels, copy its jar as well.

Example with custom panels (see the inline XML comments for more details):

Some key points:

  • The first execution section configures the copying of our application jars to the lib/ directory under our staging directory (i.e., target/staging/lib). Note that we have to explicitly exclude the IzPack dependency as well as any custom panels dependency. We don't need these showing up in our installed application!
  • The second execution section configures the copying of our custom panels jar to the custom/ directory under our staging directory (i.e., target/staging/custom). Note that we explicitly include our custom panels dependency so that no other jars are copied to custom/. It wouldn't hurt anything if this happened, but why do unnecessary work?
The maven-dependency-plugin is very configurable. You may need to customize some of this configuration for your own purposes.
Configure the izpack-maven-plugin
  • Add the base directory to the  izpack-maven-plugin. This is our staging area.
  • Add the location of  the install file.

 

Create Your Installer Descriptor

Your installer descriptor should reference resources and jars relative to the staging area. For example, here is a resources section in our installer descriptor (i.e., install.xml):

Note: these resources are originally under src/izpack. They are copied from this directory to the staging area, where the IzPack compiler will look for them.

Summary

When finished, the entire build section of our pom should look something like this:

Using Custom Panels

If you have custom panels, they should be developed in a separate Maven project. This is a standard Maven project, but you should include izPack as a provided dependency:

We use scope = provided because we only need Maven to use the IzPack dependency at compile time.

In this project, you can create your custom IzPack panels.

Be sure that the Java package names that contain your custom IzPack panels begin with "com", "net", or "org", or else they will not be able to be loaded by your IzPack installer.

 
As mentioned above, you will need to include an execution of the maven-dependency-plugin to copy the custom panel jar to the staging area.

This example include a section for custom panels which may be omitted if it does not apply.

Some key points:
  • Even though the custom panels dependency is declared as a project dependency, it also must be declared as a dependency to the IzPack plugin itself, or else you will see classloading errors. Maven gives every plugin execution its own classloader, which cannot see the classpath of the project itself.
Add the <execution> section
  • Add the second execution section to copying of the custom panels jar to the custom/ directory under our staging directory (i.e., target/staging/custom). Note that we explicitly include our custom panels dependency so that no other jars are copied to custom/. It wouldn't hurt anything if this happened, but why do unnecessary work.
Summary

When finished, the entire build section of the pom should look something like this:

 

Add the custom panel jar to the installer description

Also, don't forget to tell the IzPack compiler about your custom panels jar in the <resources> element in your install.xml file:

<jar src="custom/mycustompanels.jar"/>

Note

Icon

You should see now why we use the <stripVersion>true</stripVersion> option of the maven-dependency-plugin, so that it copies the custom jar dependency without the version in its name. This way, we can reference our custom panels jar from our installer descriptor without having to know its version.

Add custom panel to the list of panels

Here's an example of referencing a custom panel. Again, in our installer descriptor:

Note that we use the fully qualified name of the panel class.

 

Troubleshooting

There are a few simple things to check if your installer is not created properly. 

  • Read the Maven logs to be sure that no errors are reported.
  • Check the staging area to make sure that it contains all of the assets that you expected.
  • Check the install.xml file to be sure that all panels are included and that all of the pack descriptions are correct.
  • Check that all of the referenced specification files exist with the correct names and have the correct contents.
  • Watch for case sensitivity if this applies to the environment. 

References

[1] http://izpack.codehaus.org/izpack-maven-plugin/

[2] https://github.com/aspear/izpack5-example-installer

  • No labels

1 Comment

  1. I would propose a slightly different maven layout with an extra "package" module.

    izpack-seed
    +-application
    +-install
    |    \-package
    |    \-panel
    |    \-installer

    I found this way much easier to set up the targeted installation layout for my app (using maven assembly plugin for instance).

    I illustrated this approach in a github project izpack-seed