DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • How to Submit a Post to DZone
  • DZone's Article Submission Guidelines
  • Structured Logging
  • Effective Java Collection Framework: Best Practices and Tips

Trending

  • How to Submit a Post to DZone
  • DZone's Article Submission Guidelines
  • Structured Logging
  • Effective Java Collection Framework: Best Practices and Tips
  1. DZone
  2. Coding
  3. Java
  4. How to Change a NetBeans Platform Executable Icon with Maven

How to Change a NetBeans Platform Executable Icon with Maven

Timon Veenstra user avatar by
Timon Veenstra
·
Jan. 23, 13 · Interview
Like (0)
Save
Tweet
Share
10.46K Views

Join the DZone community and get the full member experience.

Join For Free

When 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

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: