Andreas Nerlich
« grails canoo webtest : verifyXPath
wiesn 2009 »
using izpack2exe from an unpacked maven dependency (19 Oct 2009) - tagged as dev, izpack
izpack

using maven, i wanted to be able to create an exe installer from an already izpack created jar installer on both unix and windows operating systems.

izpack utilities describes how one is able to do so with either the python script or with the ready made exe (izpack2exe.exe). what was missing was how to do this with maven relying only on maven repository published izpack dependencies. with this article i'd like to demonstrate how i achieved this.

in summary, the article describes the following:

  • add izpack-standalone-compile as a dependency
  • unpack the zip dependency with the maven-dependency-plugin
  • and finally execute the operating system family applicable script/exe using the maven-antrun-plugin.

for starters add the compiler dependency. most likely you will already have this dependency, because without it you are not able to do any izpack related stuff.

<dependency>
 <groupId>org.codehaus.izpack</groupId>
 <artifactId>izpack-standalone-compiler</artifactId>
</dependency>

thanks to dan tran, one is able to retrieve the necessary izpack2exe scripts packaged within a zip file deployed along side the izpack-standalone-compiler. this zip file is named izpack-standalone-compiler-<version>-izpack2exe.zip. now that we know that, we are able to unpack the zip. the unpacking is made possible using the maven-dependency-plugin unpack goal. alongside the groupId & artifactId, note the classifier and type elements. these correctly identify the dependency. lastly specify where you wish the contents to be unpacked (outputDirectory - [staging.dir is a custom property, in my case it has the value ${project.build.directory}/staging])

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>unpack-shared-resources</id>
      <goals>
        <goal>unpack-dependencies</goal>
      </goals>
      <phase>generate-resources</phase>
      <configuration>
        <includeGroupIds>org.codehaus.izpack</includeGroupIds>
        <includeArtifacIds>izpack-standalone-compiler</includeArtifacIds>
        <classifier>izpack2exe</classifier>
        <type>zip</type>
        <excludeTransitive>true</excludeTransitive>
        <outputDirectory>${staging.dir}</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

now that we have it unpacked, we are able to access the scripts and create an exe installer using the maven-antrun-plugin. i've separated the izpack unix and windows variants into profiles, each activated based on the operating system value. for the unix profile, python and 7-zip already need to be installed. without these dependencies, the execution will not succeed. furthermore, to accommodate automatic privileges elevation on windows (including vista) i've named the output file install.exe.

<profile>
  <id>izpack-exe-unix</id>
  <activation>
    <activeByDefault>false</activeByDefault>
    <os>
      <family>unix</family>
    </os>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>IzPack-Platform-Executable</id>
            <phase>install</phase>
            <configuration>
              <tasks>
                <exec executable="python" dir="${project.build.directory}">
                  <arg value="${staging.dir}/izpack2exe/izpack2exe.py" />
                  <arg value="--file=${project.build.finalName}-installer.jar" />
                  <arg value="--no-upx" />
                  <arg value="--output=install.exe" />
                </exec>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

the profile for the windows family is similar except for the activation :

<activation>
  <activeByDefault>false</activeByDefault>
  <os>
    <family>windows</family>
  </os>
</activation>

and lastly the exec. note that for the windows profile, python and 7-zip are not required as already installed programs.

<exec executable="${staging.dir}/izpack2exe/izpack2exe.exe" dir="${staging.dir}/izpack2exe">
  <arg value="--file=${project.build.directory}/${project.build.finalName}-installer.jar" />
  <arg value="--no-upx" />
  <arg value="--with-7z=${staging.dir}/izpack2exe/7za.exe" />
  <arg value="--output=${project.build.directory}/install.exe" />
</exec>

except for ${staging.dir}, all the other placeholders are built-in maven properties.

that should cover it. i hope the article helped! PS: if you're using hudson, you may notice that the exe will not appear as a downloadable build artifact. i enabled this by using maven's assembly plugin. feel free to get in touch if you need more info.

maven • izpack 
comments (2)