How to Change a NetBeans Platform Executable Icon with Maven
Join the DZone community and get the full member experience.
Join For FreeWhen building an application based on the NetBeans rich client platform, you probably want to ship it eventually with your own branding. One part of this branding is the icon of the executable.
Since icons are binary embedded into windows executables, we need an external tool to hack our own branded icon into the generated executable. This post describes how to do this using maven as a build tool.
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>
Icon
Executable
Apache Maven
NetBeans
Opinions expressed by DZone contributors are their own.
Trending
-
How to Submit a Post to DZone
-
DZone's Article Submission Guidelines
-
Structured Logging
-
Effective Java Collection Framework: Best Practices and Tips
Comments