Developers, Developers, Developers! Maksim Sorokin IT Blog

28Feb/11Off

Developing and debugging IzPack panels in Eclipse

Here I will describe how one can develop and debug own IzPack panels using Eclipse.

First go and download IzPack. We will use 4.3.3 vesion here.
After installation you will find source directory src\lib in installation location. Import it into Eclipse. Or create a Java project in Eclipse and copy sources afterwards. Obviously, project has some dependencies, so in Java Build Path add all external jars from IzPack installation folder lib. Now you should not have any errors. IzPack code is now browsable.

You can have a maven project for your custom IzPack panels. It is straight forward creation of Maven project, so I will omit it here. I will just assume, that you have a Java project for your panel.

Link you Java project to IzPack libraries, which are located in lib folder of IzPack installation. Please note, that you should not link to imported IzPack project in your Eclipse, because we will need it later on for debugging the panel -- in this case you would have cyclic dependency. Do that in project properties Java Build Path.

According to documentation, panels classes have to be created in com.izforge.izpack.panels. In your project create a package with that name. Now in that package create class MyPanel:

package com.izforge.izpack.panels;

import com.izforge.izpack.installer.InstallData;
import com.izforge.izpack.installer.InstallerFrame;
import com.izforge.izpack.installer.IzPanel;

public class MyPanel extends IzPanel {

  private static final long serialVersionUID = -2686831922771063920L;

  public MyPanel(InstallerFrame parent, InstallData idata) {
    super(parent, idata);
  }

  @Override
  public void panelActivate() {
    System.out.println("Hello, IzPack");
  }
}

Let's create a test IzPack installation, which would use our new panel. Basically, just create "install.xml" file in any folder. I will do that in c:\projects\test25\src\main\resources. Here are the internals of install.xml:

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

<installation version="1.0">

  <info>
    <appname>Test 25</appname>
    <appversion>1.0</appversion>
    <uninstaller write="no" />
    <javaversion>1.6</javaversion>

    <pack200 />
  </info>

  <guiprefs resizable="yes" width="500" height="340">
    <modifier key="allXGap" value="5" />
    <modifier key="allYGap" value="5" />
    <modifier key="paragraphYGap" value="15" />
    <modifier key="useHeadingPanel" value="yes" />
    <modifier key="headingLineCount" value="1" />
    <modifier key="headingFontSize" value="2" />
    <modifier key="headingBackgroundColor" value="0x00ffffff" />
    <modifier key="headingPanelCounter" value="text" />
    <modifier key="headingPanelCounterPos" value="inHeading" />
  </guiprefs>

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

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

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

</installation>

Now, here is the development flow. You modify the panel code. Then you run IzPack compiler from Eclipse and IzPack installer, also from Eclipse. Just two button clicks!

Here is how you configure it. Navigate to com.izforge.izpack.compiler.Compiler class in imported IzPack project in Eclipse. In menu choose "Run->Profile Configurations..". In "Java Application" on the left create new application entry. In "Main" tab in "Project" choose "izpack" in Main class choose "com.izforge.izpack.compiler.Compiler". In "Arguments" tab write "c:\projects\test25\src\main\resources\install.xml -b c:\projects\test25\src\main\resources -o c:\projects\test25\target\out -h "c:/Program Files/Izpack-4.3.3"", where you specify path to install.xml, where installer jar will be outputed and home path to IzPack installation.

Now, all we need is to tell IzPack, which installer we want to debug. In "Compiler" run configuration we specified the output of Compiler. Right-click "izpack" project and in Build Path specify that jar (which you specified in -o option).

Now you can simply call main class com.izforge.izpack.installer. GUI installer will be launched and you will be able to see all the output in the console. You can run in Debug mode as well.

So again, first modify the code. Then run Compiler and then run Installer.

Comments (0) Trackbacks (1)

Leave a comment