Skip to main content
Last updated January 23, 2013 13:52, by Timon Veenstra
Feedicon  

Developers FAQ Create Installers


How to run from maven

The build installers need to be called from commandline (mvn nbm:build-installers) the context menu action does not do the same and does not read custom configuration in your pom

Plugin configuration

The configuration of the nbm-maven-plugin is placed in the build -> pluginManagement section of the parent pom (myProject/pom.xml)
The configuration of the ant task (maven-antrun-plugin) replacing the icon is placed in the build -> plugins section of the application pom (myProject/application/pom.xml)
The icon change needs to be hooked in the build process of only the application and not of all modules in the application.

The complete configuration

  • run mvn nbm:build-installers once in your myProject/application folder
  • copy myProject/application/target/installer/nbi/stub/template.xml to myProject/application/installer/template.xml
  • copy your own 48x48 png or gif icon to myProject/application/installer/
  • create a .ico file from your png icon with the gimp or another graphical editor

myProject/pom.xml:

...
    <properties>
        <brandingToken>agrosense</brandingToken>
        <application.ico>${basedir}/installer/agrosense.ico</application.ico>
...
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>nbm-maven-plugin</artifactId>
                    <version>3.8.1</version>
                    <extensions>true</extensions>
                    <configuration>
                        <brandingToken>${brandingToken}</brandingToken>
                        <cluster>${brandingToken}</cluster>
                        <etcConfFile>${basedir}/installer/application.conf</etcConfFile>
                        <templateFile>${basedir}/installer/template.xml</templateFile>
                         <userSettings>
                            <releaseVersion>${releaseVersion}</releaseVersion>
                            <!-- this will replace the icon in the upper left corner of the installation wizard -->
                            <nbi.instleftcorner.file>${basedir}/installer/agrosense_icon48.png</nbi.instleftcorner.file>
                            <!-- this will replace the icon file in the installed application folder -->
                            <nbi.icon.file>${basedir}/installer/agrosense_icon48.png</nbi.icon.file>
                        </userSettings>                    
                    </configuration>
                </plugin>

  • install Resource Hacker (when using linux, first install java in a wine bottle and then install Resource Hacker in the same bottle)
  • add local configuration profile to your ~/.m2/settings.xml (change when needed):

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>replace-icon-config</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <wine.bottle>${user.home}/.bottles/iconFixer</wine.bottle>
                <resourcehacker.installdir>C:\Program Files (x86)\Resource Hacker\</resourcehacker.installdir>
            </properties>
        </profile>
    </profiles>
</settings>

  • add the following profiles to your myProject/application/pom.xml. (they are not application specific, so they should work without adjustment)

         <profile>
            <id>replace-icon-unix</id>
            <activation>
                <os>
                    <family>Unix</family>
                </os>
                <file>
                    <exists>${wine.bottle}\drive_c\${resourcehacker.installdir}\ResHacker.exe</exists>
                </file>                     
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId> 
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>                        
                                <configuration>
                                    <target> 

                                        <echo message ="Replacing icon of Windows launcher executable" /> 
                                        <!-- replace executable with ResHacker.exe path on windows -->
                                        <exec executable="wine" resolveexecutable="true" logerror="true">
                                            <!-- replace value with location of installation bottle, or remove on windows -->
                                            <env key="WINEPREFIX" value="${wine.bottle}" />
                                            <!-- remove this argument when running on windows -->
                                            <arg value="${resourcehacker.installdir}\ResHacker.exe"/>
                                            <arg value="-addoverwrite"/>
                                            <arg value="${project.build.directory}/${brandingToken}/bin/${brandingToken}.exe,"/>
                                            <arg value="${project.build.directory}/${brandingToken}/bin/${brandingToken}.exe,"/>
                                            <arg value="${application.ico},"/>
                                            <arg value="ICONGROUP,"/>
                                            <arg value="MAINICON,"/>
                                            <arg value="0"/>
                                        </exec>      
                     
                                        <zip destfile="${project.build.directory}/${project.artifactId}-${project.version}.zip" update="true"> 
                                            <zipfileset dir="${project.build.directory}/${brandingToken}/bin" includes="*.exe" prefix="${brandingToken}/bin" /> 
                                        </zip>            
                                    </target>       
                                </configuration>                      
                            </execution>
                        </executions>
                    </plugin>  
                </plugins>
            </build>
        </profile>                    
        <profile>
            <id>replace-icon-windows</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
                <file>
                    <exists>${resourcehacker.installdir}\ResHacker.exe</exists>
                </file>                            
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId> 
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>                        
                                <configuration>
                                    <target> 

                                        <echo message ="Replacing icon of Windows launcher executable" /> 
                                        <!-- replace executable with ResHacker.exe path on windows -->
                                        <exec executable="${resourcehacker.installdir}\ResHacker.exe" resolveexecutable="true" logerror="true">
                                            <arg value="-addoverwrite"/>
                                            <arg value="${project.build.directory}/${brandingToken}/bin/${brandingToken}.exe,"/>
                                            <arg value="${project.build.directory}/${brandingToken}/bin/${brandingToken}.exe,"/>
                                            <arg value="${application.ico},"/>
                                            <arg value="ICONGROUP,"/>
                                            <arg value="MAINICON,"/>
                                            <arg value="0"/>
                                        </exec>      
                     
                                        <zip destfile="${project.build.directory}/${project.artifactId}-${project.version}.zip" update="true"> 
                                            <zipfileset dir="${project.build.directory}/${brandingToken}/bin" includes="*.exe" prefix="${brandingToken}/bin" /> 
                                        </zip>            
                                    </target>       
                                </configuration>                      
                            </execution>
                        </executions>
                    </plugin>                       
                </plugins>                  
            </build>
        </profile>

Names and versions

With the release of nbm-maven-plugin version 3.7 it is again possible to generate platform specific installers for your maven based Netbeans platform application. Building installers context menu action will work pretty much out of the box. It will generate a few names you likely prefer to be different:

  1. application-1.0.20-linux.sh should be AgroSense-1.0.20-linux.sh
  2. installer name is artifactId of the parent pom, parent-core in our case
  3. installed directory is cloudfarming (which was our branding token at the time)
  4. executable is cloudfarming.exe

solutions:

  1. The name of your nbm-application project is used for this. While the directory can remain application you should change the name (and artifactId to keep it consistent). for example:
    <name>AgroSense</name>

    which will result in AgroSense-1.0.20-linux.sh
    Beware, artifactId is used to determine the name of the zip, name is used to determine the name of the installers!
    you can overide this with the property:
    <installersFilePrefix>AgroSense</installersFilePrefix>
  2. Your application parent artifact id will be used as app name
    String appName = project.getParent().getArtifactId().replace( ".", "" ).replace( "-", "" ).replace( "_", "" ).replaceAll( "[0-9]+", "" );

    So you better choose something sensible unlike parent-core ;)
  3. From the default used template.xml:
                <property name="suite.props.app.name"  value="${pom.props.project.properties.brandingToken}"/>
    ...
                <replacefilter token="{product-install-directory-name}"         value="${suite.props.app.name}"/>
                <replacefilter token="{product-install-directory-name-windows}" value="${suite.props.app.name}"/>
                <replacefilter token="{product-install-directory-name-macosx}"  value="${suite.props.app.name}"/>
    
  4. Name of the executable seems to be directly coming from the branding token configured in the parent pom. From the default used template.xml:
                <property name="suite.props.app.name"  value="${pom.props.project.properties.brandingToken}"/>
    ...
                <property name="suite.dist.zip"       value="${suite.dist.directory}/${suite.props.app.name}.zip"/>
                <property name="installers.file.prefix" value="${suite.props.app.name}"/>
    


Remarks:

  • your branding token should match your parent artifactId (TODO:check, could be something else) otherwise the installer build target cannot find your unzipped application since it is used for "{product-data-sub-dir}"
  • Combination of 2, 4 and 5 seem to indicate the rule that the brandingToken should equal the artifactId without signs as "-_.[0-9]"
  • branding token is also used as default installation dir, no matter what value for installDirName is set


The Icon

By default the icon of the installed application is an orange box.

  1. Add the nbi.icon.file to your pom to load a custom icon
    <configuration>
           <userSettings>
                   <nbi.icon.file>${project.build.directory}\resources\icons\icon.png</nbi.icon.file>
           </userSettings>
    </configuration>

To also change the icon of the installed executable we need to hook into the packaging cycle. The solution provided in http://wiki.netbeans.org/DevFaqExecutableIcon does not seem to work for maven applications. What did work was to change the icon in the package phase instead of the build installers phase. Added following plugin to the pom of the application project:

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId> 
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>                        
                        <configuration>
                            <target> 
                                <echo message ="Replacing icon of Windows launcher executable" /> 
                                <exec executable="wine" resolveexecutable="true" failifexecutionfails="false" logerror="true">
                                    <env key="WINEPREFIX" value="/home/monezz/.bottles/iconFixer/" />
                                    <arg value="C:\Program Files (x86)\Resource Hacker\ResHacker.exe"/>
                                    <arg value="-addoverwrite"/>
                                    <arg value="${project.build.directory}/shpxmlconverter/bin/shpxmlconverter.exe, "/>
                                    <arg value="${project.build.directory}/shpxmlconverter/bin/shpxmlconverter.exe,"/>
                                    <arg value="${basedir}/installer/sxc.ico, "/>
                                    <arg value="ICONGROUP,"/>
                                    <arg value="MAINICON,"/>
                                    <arg value="0"/>
                                </exec>                                 
                                 <zip destfile="${project.build.directory}/shp-xml-converter-${project.version}.zip" update="true"> 
                                    <zipfileset dir="${project.build.directory}/shpxmlconverter/bin" includes="*.exe" prefix="shpxmlconverter/bin" /> 
                                </zip>            
                            </target>       
                        </configuration>                      
                    </execution>
                </executions>
            </plugin>
When run on linux, the Resource hacker tool (available here) needs to be installed in the provided WINEPREFIX bottle (/home/monezz/.bottles/iconFixer/ in my case). Ofcourse this is a bad thing because since it will only work on one machine However, delivering an application with an orange box as icon to a client is just not an option. When wine or the icon fixer is not available the task should fail silently. When run on windows, the wine executable can be replaced by the full path to the ResHacker.exe (and remove env and first arg children).

Configuration

Things that appear to be broken

  • having a finalName property in your root pom, will cause your branding module to be renamed and broken

                    <finalName>AgroSense-1.0.20</finalName>


Tips

Marcelo Schneider Marcelo.Schneider@marinecyb.com:

However, <nbi.icon.file> only defines the installer's frame icon - same with your installer, both the installer and the runnable program for AgroSense use the default NetBeans icons...

By the way, those properties can also be defined on your pom.xml with

 
<configuration>
       <userSettings>
               <nbi.icon.file>${project.build.directory}\resources\icons\icon.png</nbi.icon.file>
       </userSettings>
</configuration>
 

So there's no need to change the template (I changed it either way, but for other reasons) (:

> 2. https://jira.codehaus.org/browse/MNBMODULE-173 > 3. https://jira.codehaus.org/browse/MNBMODULE-174

 
 
Close
loading
Please Confirm
Close