HOWTO: Customize installers generated by nbm:build-installers

Generated installers can be customized by providing user-defined customized templateFile and pass parameters to it with userSettings parameter. See build-installers goal description.

User defined template can be used to modify generated installer behavior, e.g. branding of installation environment etc.

Example 1: Simple change in installer code

Simple changes into original Harness installer code can be made by filtering corresponding file using Ant in templateFile.

Following code added into prepare-sources target takes rid of the "Run application when installer finished" checkbox at the last page of installer wizard:

<replace file="${installer.build.dir}/ext/engine/src/org/mycompany/installer/wizard/components/panels/PostInstallSummaryPanel.java" 
    encoding="utf-8">
    <replacefilter token="runAppNow.doClick();"        value="runAppNow.setVisible(false);"/>
</replace>

Example 2: More complex installer code changes

If the code changes become more complex better solution is to replace entire Harness files with modified versions.

For example, you would like to register file associations for your application.

First of all, prepare your modified version of the file ConfigurationLogic.java according to the instructions at http://wiki.netbeans.org/NBIFileAssosiations.

As a next step add a copy task into prepare-sources target in your templateFile:

<copy file="${configuration.logic.file}"  overwrite="true"
   tofile="${installer.build.dir}/ext/components/products/helloworld/src/org/mycompany/ConfigurationLogic.java"/>

and finally define configuration.logic.file parameter in the application's pom:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>nbm-maven-plugin</artifactId>
    <configuration>
        <templateFile>${basedir}/installer/template.xml</templateFile>
        <userSettings>
            <configuration.logic.file>${basedir}/installer/ConfigurationLogic.java</configuration.logic.file>
        </userSettings>
    </configuration>
</plugin>

Example 3: Branding of installer images

If installer left corner image has to be branded, following code can be added to templateFile target prepare-sources:

<condition property="ilc.path" value="${nbi.instleftcorner.file}">
     <and>
         <isset property="nbi.instleftcorner.file"/>
         <available file="${nbi.instleftcorner.file}"/>
     </and>
</condition>
<condition property="ilc.defined">
     <and>
         <isset property="nbi.instleftcorner.file"/>
         <available file="${nbi.instleftcorner.file}"/>
     </and>
</condition> 
<antcall target="-prepare-ilc"/>

In addition, new target -prepare-ilc has to be defined, e.g. at the end of templateFile:

<target name="-prepare-ilc" if="ilc.defined">
    <copy file="${ilc.path}" tofile="${installer.build.dir}/ext/engine/src/org/mycompany/installer/wizard/wizard-description-background-left.png" overwrite="true"/>
</target>

which effectively replaces the desired image.

Finally, update application's pom:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>nbm-maven-plugin</artifactId>
    <configuration>
        <templateFile>${basedir}/installer/template.xml</templateFile>
        <userSettings>
            <nbi.instleftcorner.file>${basedir}/installer/ilc.png</nbi.instleftcorner.file>
        </userSettings>
    </configuration>
</plugin>

More information: http://wiki.netbeans.org/NBI