При создании приложения на основе многофункциональной клиентской платформы NetBeans вы, вероятно, захотите в конечном итоге выпустить его под собственным брендом. Одной из частей этого бренда является значок исполняемого файла.
Поскольку значки являются двоичными файлами, встроенными в исполняемые файлы Windows, нам нужен внешний инструмент, чтобы взломать наш собственный фирменный значок в сгенерированный исполняемый файл. Этот пост описывает, как сделать это, используя maven в качестве инструмента для сборки.
Полная конфигурация
- запустить MVN NBM: Строить-монтажник раз в MyProject / прикладную папке
- скопируйте myProject / application / target / installer / nbi / stub / template.xml в myProject / application / installer / template.xml
- скопируйте свой собственный значок 48×48 png или gif в myProject / application / installer /
- создайте файл .ico из иконки png с помощью gimp или другого графического редактора
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>
- установить Resource Hacker (при использовании linux сначала установите Java в бутылку вина, а затем установите Resource Hacker в ту же бутылку)
- добавьте профиль локальной конфигурации в ваш ~ / .m2 / settings.xml (при необходимости измените):
<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>
- добавьте следующие профили в ваш myProject / application / pom.xml . (они не привязаны к конкретному приложению, поэтому должны работать без настройки)
<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>