dimanche 24 avril 2011

Automating application installation - skeleton

In a previous post, we explained how any server and application installation could be automated using IzPack. In this post, we are going to decrypt the smallest configuration that may be used to build an IzPack installer from a Maven project.


Goals

At the end of this tutorial, we will have a project that meets the following requirements :

  • The project is built using Maven
  • It packages an IzPack installer
  • It will have only 2 panels (a "Welcome" panel and a "Installation Complete !" panel)
  • It does not perform any installation operation

Setting up the project

Let's start this tutorial by a simple operation : we need to create a maven project. To do so, we use the command mvn archetype:generate . When prompted, choose the artifact maven-archetype-quickstart, which is the default one.

$ mvn archetype:generate
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[...]
Choose a number:  (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41/42/43/44/45/46) 20: :
[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from central
Define value for groupId: : fr.pingtimeout
Define value for artifactId: : izpack-environment-installer
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  fr.pingtimeout: :
Confirm properties configuration:
groupId: fr.pingtimeout
artifactId: izpack-environment-installer
version: 1.0-SNAPSHOT
package: fr.pingtimeout
 Y: :
[...]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 59 seconds
[INFO] Finished at: Tue Apr 19 17:20:49 CEST 2011
[INFO] Final Memory: 8M/14M
[INFO] ------------------------------------------------------------------------

Modifying the Maven project

The archetype maven-archetype-quickstart is the perfect one for us since it does not come with anything except the basic structure of any project and empty files.

First, we need to delete those files (src/main/java/App.java and src/test/java/AppTest.java). Then, we need to create the src/main/resources/ folder. It will contain the configuration of our installer.

Let's now modify the pom.xml so that we don't have à dependency to an old version of JUnit anymore. Add a new block that will package our installer during the Maven "package" phase. This new block will be parametrised by the following elements :

  • A property defines the version of IzPack we want to use
  • Another property refers to the working directory Maven will use to build the installer
  • The plugin maven-izpack-plugin is executed during the "package" package phase with the previous properties
  • The plugin maven-resources-plugin is used to copy our project resources in the working folder
Here is our new 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/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>fr.pingtimeout</groupId>

 <artifactId>izpack-maven-empty-model</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>pom</packaging>

 <name>izpack-maven-empty-model</name>

 <url>http://www.pingtimeout.fr/</url>

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <izpack.staging.dir>${project.build.directory}/izpack-staging</izpack.staging.dir>

  <izpack.standalone.compiler.version>4.3.2</izpack.standalone.compiler.version>
 </properties>

 <build>
  <plugins>
   <!-- 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>${izpack.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>${izpack.staging.dir}</outputDirectory>
       <resources>
        <resource>
         <directory>src/main/resources</directory>

        </resource>
       </resources>
      </configuration>
     </execution>
    </executions>
   </plugin>

  </plugins>
 </build>
</project>

IzPack configuration

The only thing that remains on our Todo list is to configure IzPack so that it builds our empty installer. First, we need an installer descriptor (a file named install.xml in src/main/resources/). This file contains the following elements.

In the info section, we tell IzPack that :

  • Our application is named "IzPack empty Model"
  • The current installer's version is 1.0
  • We do not want an uninstaller to be built
  • Java 1.6 must be installed
  • Our installer is compressed using the Pack200 algorithm

It is available in French and is executed in a resizable window of 640x480 pixels.

In the panels section, we define 2 screens. The first one is a basic welcome screen. The second one is a generic "Installation complete !" screen.

Finally, we define the lists of files that may be copied by the installer (a list is called a "pack"). In this tutorial, there is no such file. However, the IzPack documentation tells us that at least one pack is required, so let's create an empty one.


Building the installer

That's it. The whole Maven project is ready. The only thing we have to do is to package our installer by building our project with the usual mvn package.

$ mvn clean package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building izpack-maven-empty-model
[INFO]    task-segment: [clean, package]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] [resources:copy-resources {execution: copy-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] [site:attach-descriptor {execution: default-attach-descriptor}]
[INFO] [izpack:izpack {execution: default}]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11 seconds
[INFO] Finished at: Thu Apr 21 11:54:40 CEST 2011
[INFO] Final Memory: 11M/21M
[INFO] ------------------------------------------------------------------------

Here are some screenshots of an installer based on this tutorial.

Panel 1 - Welcome

Panel 2 - Installation complete !


Conclusion

This tutorial allows us to set up IzPack pretty quickly in a Maven project. Ideally, it could even be used to create a Maven artifact.

Now, to make full use of IzPack, we need to read the official documentation (which is very complete).


Resources

The resources that were used during this tutorial are available using the following links :

Still not convinced by the power of IzPack or its easy integration in any project ? Tell us about it in the comments !

Aucun commentaire:

Enregistrer un commentaire