简体   繁体   English

自包含JavaFX应用程序中的包含图标

[英]Include icon in Self-Contained JavaFX application

I've been fighting with this for over a day and have read many posts on SO and other places, but I'm still having problems. 我已经为此争取了一天多的时间,并且在SO和其他地方阅读了许多帖子,但是我仍然遇到问题。

I need to include my application icon in a self-contained JavaFX application package. 我需要在一个自包含的JavaFX应用程序包中包含我的应用程序图标。 I'm using JDK 1.8.0_45 and its included JavaFX package. 我正在使用JDK 1.8.0_45及其随附的JavaFX软件包。 I'm using Maven to build the .exe and it all works great except I can't get my icon included. 我正在使用Maven来生成.exe,并且所有工作都很好,但无法包含我的图标。

Here is my pom.xml: 这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <prerequisites>
        <maven>2.2.1</maven>
    </prerequisites>

    <groupId>com.mycompany.drm</groupId>
    <artifactId>DRMDashboard</artifactId>
    <version>2.0</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javafx.version>8.0.45</javafx.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <!-- copy all dependencies of your app to target folder-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <configuration>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <JavaFX-Version>${javafx.version}+</JavaFX-Version>
                            <Main-Class>com.mycompany.client.HelloWorld</Main-Class>
                            <implementation-version>2.0</implementation-version>
                            <JavaFX-Application-Class>com.mycompany.client.HelloWorld</JavaFX-Application-Class>
                            <JavaFX-Class-Path>
                                <!-- list all your dependencies here-->

                            </JavaFX-Class-Path>
                            <!-- The artifactId (name) of the jfxrt.jar ... see dependency system scope-->
                            <Class-Path>
                                javafx-${javafx.version}.jar
                            </Class-Path>
                        </manifestEntries>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>

                                <path id="mypath">
                                    <pathelement path="${maven.plugin.classpath}"/>
                                    <fileset dir="${project.basedir}">
                                        <include name="package/windows/DRMDashboard.ico"/>
                                    </fileset>
                                </path>

                                <!-- define the deploy ANT task-->
                                <taskdef name="jfxdeploy" classname="com.sun.javafx.tools.ant.DeployFXTask"
                                         classpathref="mypath" />
                                <!-- define the JarSign ANT task-->
                                <taskdef name="jfxsignjar" classname="com.sun.javafx.tools.ant.FXSignJarTask"
                                         classpathref="maven.plugin.classpath" />
                                <jfxdeploy outdir="${project.build.directory}/deploy"
                                           outfile="DRMDashboard"
                                           nativeBundles="exe"
                                           verbose="true">
                                    <info title="DRM Dashboard" vendor="My Company, Inc."/>
                                    <application name="DRMDashboard" mainClass="com.mycompany.client.HelloWorld" version="2.0" />
                                    <resources>
                                        <fileset dir="${project.build.directory}" includes="*.jar" />
                                                 <!--includes="*.jar" />-->
                                    </resources>
                                    <!-- set your jvm args-->
                                    <platform javafx="${javafx.version}+">
                                        <jvmarg value="-Xms512m" />
                                        <jvmarg value="-Xmx1024m" />
                                    </platform>
                                    <preferences install="false" menu="true" shortcut="true"/>
                                </jfxdeploy>
                                <!-- you need to generate a key yourself -->
                                <jfxsignjar destdir="${project.build.directory}/deploy"
                                            keyStore="c:/Users/me/DRMDashboard.ks" storePass="****" alias="DRMDashboard"
                                            keyPass="****">
                                    <fileset dir="${project.build.directory}/deploy"
                                             includes="*.jar" />
                                </jfxsignjar>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ant-javafx</artifactId>
                        <version>${javafx.version}</version>
                        <systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
                        <scope>system</scope>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
        <finalName>DRMDashboard</finalName>
    </build>
</project>

EDIT 1: Here's a screenshot of my file explorer: 编辑1:这是我的文件浏览器的屏幕截图: 在此处输入图片说明

EDIT 2: Here's a screenshot of the expanded target folder: 编辑2:这是扩展的目标文件夹的屏幕截图: 在此处输入图片说明

When I execute the build with the verbose flag, I get these messages: 当我使用详细标志执行构建时,得到以下消息:

main:
No base JDK. Package will use system JRE.
  Using default package resource [application icon]  (add package/windows/DRMDashboard.ico to the class path to customize)
Icon File Name: C:\Users\jernst\AppData\Local\Temp\fxbundler8622978628378929412\windows\DRMDashboard.ico
Executable File Name: C:\Users\jernst\AppData\Local\Temp\fxbundler8622978628378929412\images\win-exe.image\DRMDashboard\DRMDashboard.exe
  Config files are saved to C:\Users\jernst\AppData\Local\Temp\fxbundler8622978628378929412\windows. Use them to customize package.
  Using default package resource [Inno Setup project file]  (add package/windows/DRMDashboard.iss to the class path to customize)
  Using default package resource [setup dialog icon]  (add package/windows/DRMDashboard-setup-icon.bmp to the class path to customize)
Using default package resource [script to run after application image is populated]  (add package/windows/DRMDashboard-post-image.wsf to the class path to customize)

I've tried using the "Drop In Resources" as described in the Oracle Documentation , but no matter what I try to get the classpath right, it won't recognize my custom icon 我已经尝试使用Oracle文档中所述的“拖放资源”,但是无论我如何正确设置类路径,它都无法识别我的自定义图标

EDIT 3: I used NwDx's suggested approach of using the javapackager instead of the ant task and I've gotten very close to what I need. 编辑3:我使用了NwDx建议的使用javapackager而不是ant任务的方法,并且我已经非常接近我需要的东西了。 Now my only problem is that the dialog box icon still uses the generic java coffee cup: 现在我唯一的问题是对话框图标仍然使用通用的Java咖啡杯: 在此处输入图片说明

Here's my current POM: 这是我当前的POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <prerequisites>
        <maven>2.2.1</maven>
    </prerequisites>

    <groupId>com.autoap.drm</groupId>
    <artifactId>native_drm</artifactId>
    <version>2.0</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javafx.version>8.0.45</javafx.version>
        <mainClass>com.autoap.client.DRMDashboard</mainClass>
        <application.title>DRMDashboard</application.title>
        <organization.name>AutoAp, Inc.</organization.name>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <!-- copy all dependencies of your app to target folder-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <configuration>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <JavaFX-Version>${javafx.version}+</JavaFX-Version>
                            <Main-Class>com.autoap.client.DRMDashboard</Main-Class>
                            <implementation-version>2.0</implementation-version>
                            <JavaFX-Application-Class>com.autoap.client.DRMDashboard</JavaFX-Application-Class>
                            <JavaFX-Class-Path>
                                <!-- list all your dependencies here-->

                            </JavaFX-Class-Path>
                            <!-- The artifactId (name) of the jfxrt.jar ... see dependency system scope-->
                            <Class-Path>
                                javafx-${javafx.version}.jar
                            </Class-Path>
                        </manifestEntries>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

             <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <!-- Create the jar file -->
                    <execution>
                        <id>createjar</id>

                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>

                        <configuration>
                            <executable>${java.home}/../bin/javapackager</executable>
                            <arguments>
                                <argument>-createjar</argument>
                                <argument>-nocss2bin</argument>
                                <argument>-appclass</argument>
                                <argument>${mainClass}</argument>
                                <argument>-srcdir</argument>
                                <argument>${project.build.directory}/classes</argument>
                                <argument>-outdir</argument>
                                <argument>${project.build.directory}</argument>
                                <argument>-outfile</argument>
                                <argument>${project.build.finalName}.jar</argument>
                            </arguments>
                        </configuration>
                    </execution>

                    <!-- Sign the jar -->
                    <!-- Can't test, because I don't have the files
                    <execution>
                        <id>signjar</id>

                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>

                        <configuration>
                            <executable>${java.home}/../bin/javapackager</executable>
                            <arguments>
                                <argument>-signjar</argument>
                                <argument>-alias</argument>
                                <argument>${application.title}</argument>
                                <argument>-keyPass</argument>
                                <argument>****</argument>
                                <argument>-keyStore</argument>
                                <argument>C:/Users/me/DRMDashboard.ks</argument>
                                <argument>-storePass</argument>
                                <argument>*****</argument>
                                <argument>-outdir</argument>
                                <argument>${project.build.directory}</argument>
                                <argument>-srcdir</argument>
                                <argument>${project.build.directory}</argument>
                                <argument>-srcfiles</argument>
                                <argument>${project.build.finalName}.jar</argument>
                            </arguments>
                        </configuration>
                    </execution> -->

                    <!-- Deploy a native version -->
                    <execution>
                        <id>deploy</id>

                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/../bin/javapackager</executable>
                            <arguments>
                                <argument>-deploy</argument>
                                <argument>-appclass</argument>
                                <argument>${mainClass}</argument>
                                <argument>-native</argument>
                                <argument>exe</argument>
                                <argument>-srcdir</argument>
                                <argument>${project.build.directory}</argument>
                                <argument>-srcfiles</argument>
                                <argument>${project.build.finalName}.jar</argument>
                                <argument>-outdir</argument>
                                <argument>${project.build.directory}/dist</argument>
                                <argument>-outfile</argument>
                                <argument>${project.build.finalName}</argument>
                                <argument>-Bicon=${project.build.directory}/classes/${application.title}.ico</argument>
                                <argument>-BappVersion=${project.version}</argument>
                                <argument>-Bcopyright='2015 AutoAp, Inc.'</argument>
                                <argument>-BshortcutHint=true</argument>
                                <argument>-BsystemWide=false</argument>
                                <argument>-Bwin.menuGroup=${organization.name}</argument>
                                <argument>-Bvendor=${organization.name}</argument>
                                <argument>-v</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-cli</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/bin/java</executable>
                            <commandlineArgs>-jar '${project.build.directory}/${project.build.finalName}.jar'</commandlineArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <finalName>DRMDashboard</finalName>
    </build>
</project>

The thing that made the icon show up in the title bar is the -Bicon=${project.build.directory}/classes/${application.title}.ico argument to the javapackager deploy step. 使图标显示在标题栏中的是Javapackager部署步骤的-Bicon=${project.build.directory}/classes/${application.title}.ico参数。 That line tells the inno installer to use the icon. 该行告诉inno安装程序使用该图标。 The last piece of the puzzle is how to make inno use the bmp for the dialog box image. 最后一个难题是如何使bmp用作对话框图像。 Here's the relevant bit of the log file: 这是日志文件的相关位:

Running [C:\Program Files\Java\jdk1.8.0_45\jre\bin\java, -version]
Running [C:\Program Files (x86)\Inno Setup 5\iscc.exe, /?]
  Detected [C:\Program Files (x86)\Inno Setup 5\iscc.exe] version [5]
   Using custom package resource [application icon]  (loaded from file C:\Users\jernst\IdeaProjects\AutoAp\native_drm\target\classes\DRMDashboard.ico)
Running [C:\Users\jernst\AppData\Local\Temp\iconswap106251599206027586.exe, C:\Users\jernst\AppData\Local\Temp\fxbundler6949394438624826643\windows\DRMDashboard.ico, C:\Users\jernst\AppData\Local\Temp\fxbundler6949394438624826643\images\win-exe.image\DRMDashboard\DRMDashboard.exe]
Icon File Name: C:\Users\jernst\AppData\Local\Temp\fxbundler6949394438624826643\windows\DRMDashboard.ico
Executable File Name: C:\Users\jernst\AppData\Local\Temp\fxbundler6949394438624826643\images\win-exe.image\DRMDashboard\DRMDashboard.exe
  Config files are saved to C:\Users\jernst\AppData\Local\Temp\fxbundler6949394438624826643\windows. Use them to customize package.
  Using default package resource [Inno Setup project file]  (add package/windows/DRMDashboard.iss to the class path to customize)
  Using default package resource [setup dialog icon]  (add package/windows/DRMDashboard-setup-icon.bmp to the class path to customize)
Using default package resource [script to run after application image is populated]  (add package/windows/DRMDashboard-post-image.wsf to the class path to customize)
Generating EXE for installer to: C:\Users\jernst\IdeaProjects\AutoAp\native_drm\target\dist\bundles
Running [C:\Program Files (x86)\Inno Setup 5\iscc.exe, /oC:\Users\jernst\IdeaProjects\AutoAp\native_drm\target\dist\bundles, C:\Users\jernst\AppData\Local\Temp\fxbundler6949394438624826643\images\win-exe.image\DRMDashboard.iss] in C:\Users\jernst\AppData\Local\Temp\fxbundler6949394438624826643\images\win-exe.image
Inno Setup 5 Command-Line Compiler

You can see where it finds my custom application icon, but it's not finding the custom setup dialog icon. 您可以看到它在哪里找到我的自定义应用程序图标,但没有找到自定义安装对话框图标。

Prerequirements / Assumptions 先决条件/假设

  • You're on Windows (7, 8, 8.1) 您使用的是Windows(7、8、8.1)
  • You have a JDK installed at least in version 1.8.0 (javafx included) 您至少在1.8.0版中安装了JDK(包括javafx)
  • You've set the JAVA_HOME environment variable pointing to the top directory of your JDK (ex. C:\\Program Files\\Java\\jdk1.8.0_45) 您已将JAVA_HOME环境变量设置为指向JDK的顶级目录(例如C:\\ Program Files \\ Java \\ jdk1.8.0_45)。
  • You have Inno Setup at least in version 5.5.5 installed (prefered the unicode version) 您至少已在版本5.5.5中安装了Inno Setup (首选unicode版本)
  • You already have a icon file (256 x 256px), prefered a multisize one. 您已经有一个图标文件(256 x 256px),最好使用多尺寸的图标文件。 I recommend to visit this site: http://icoconvert.com/ 我建议访问此网站: http : //icoconvert.com/
  • You already have a bmp file (48 x 48 px) for the setup installer as setup icon 您已经有一个bmp文件(48 x 48 px)用于安装安装程序作为安装图标

Solution

Project structure 项目结构

First you need to setup the Project in a valid structure, like this: Your package folder have to be in the project root folder and not in any subfolder like src or resources. 首先,您需要以有效的结构设置Project,如下所示:您的package文件夹必须位于项目的根文件夹中,而不能位于src或resources之类的任何子文件夹中。

工程结构

pom.xml pom.xml

There are some more properties needed for doing the correct deploy. 进行正确的部署还需要一些其他属性。 As you can see in the antrun plugin section, you need to reassign the properties for your ant environment before you can call the build file. 如您在antrun插件部分中所见,您需要为ant环境重新分配属性,然后才能调用构建文件。 The properties are automatically set to the called build file. 这些属性会自动设置为调用的生成文件。 Normaly Intellij Idea will create the pom.xml for you in the project root dir. 通常,Intellij Idea将在项目根目录中为您创建pom.xml。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.autoap</groupId>
    <artifactId>HelloWorld</artifactId>
    <version>2.0</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mainClass>com.autoap.client.HelloWorld</mainClass>
        <application.title>${project.artifactId}</application.title>
        <copyright>Han Solo</copyright>
    </properties>

    <organization>
        <name>Star Wars</name>
    </organization>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <excludeScope>system</excludeScope>
                            <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/bin/java</executable>
                            <commandlineArgs>-jar '${project.build.directory}/dist/${project.build.finalName}-${project.version}.jar'
                            </commandlineArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <property name="compile_classpath" refid="maven.compile.classpath"/>
                                <property name="outputDir" value="${project.build.outputDirectory}"/>
                                <property name="sourceDir" value="${project.build.sourceDirectory}"/>
                                <property name="distDir" value="${project.build.outputDirectory}/../dist"/>
                                <property name="javaHome" value="${java.home}"/>
                                <property name="versionNo" value="${project.version}"/>
                                <property name="mainClass" value="${mainClass}" />
                                <property name="appName" value="${application.title}"/>
                                <property name="appTitle" value="${application.title}"/>
                                <property name="appVendor" value="${project.organization.name}"/>
                                <property name="appCopyright" value="${copyright}"/>
                                <property name="appMenuGroup" value="${project.organization.name}"/>
                                <ant antfile="${basedir}/build.xml" target="default"/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

build.xml build.xml

I've tried to make it loosley coupled, so there is normaly no need to change anything in that file. 我已经尝试过使它变得松散耦合,因此通常无需更改该文件中的任何内容。 Only if you want to have signing or special behaviour etc.The build.xml file should be saved in the project root dir. 仅当您想要签名或有特殊行为时,才应将build.xml文件保存在项目根目录中。

<?xml version="1.0" encoding="UTF-8" ?>

<project name="App" default="default" basedir="."
         xmlns:fx="javafx:com.sun.javafx.tools.ant">


    <target name="default" depends="clean,compile">

        <!-- defines the classpath -->
        <path id="cp">
            <filelist>
                <file name="${javaHome}/../lib/ant-javafx.jar"/>
                <file name="${basedir}" />
            </filelist>
        </path>

        <!-- defines the task with a reference to classpath -->
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                 uri="javafx:com.sun.javafx.tools.ant"
                 classpathref="cp"/>


        <fx:application id="appId"
                        name="${appName}"
                        mainClass="${mainClass}"
                        version="${versionNo}"/>


        <!-- Defines the resources needed by the application -->
        <fx:resources id="appRes">
            <fx:fileset dir="${distDir}" includes="${appName}-${versionNo}.jar"/>
        </fx:resources>

        <!-- Create a jar file -->
        <fx:jar destfile="${distDir}/${appName}-${versionNo}.jar">
            <fx:application refid="appId"/>
            <fx:resources refid="appRes"/>
            <fileset dir="${outputDir}"/>
        </fx:jar>

        <fx:deploy width="300" height="250"
                   outdir="${distDir}" embedJNLP="true"
                   outfile="${appName}-${versionNo}"
                   nativebundles="exe" verbose="true">

            <!-- define for ex. min javafx version -->
            <!-- <fx:platform /> -->

            <!-- defines the application and setup preferences -->
            <fx:preferences shortcut="true" install="true" menu="true"/>

            <!-- defines the application parts -->
            <fx:application refId="appId"/>

            <!-- defines the needed resources -->
            <fx:resources refid="appRes"/>

            <!-- defines the application info details -->
            <fx:info title="${appTitle}"
                     vendor="${appVendor}"
                     copyright="${appCopyright}"/>

            <!-- Some bundle arguments only for special platforms -->
            <fx:bundleArgument arg="win.menuGroup" value="${appMenuGroup}"/>
        </fx:deploy>

    </target>

    <!-- Removes the folders of previous runs -->
    <target name="clean">
        <mkdir dir="${outputDir}"/>
        <mkdir dir="${distDir}"/>

        <delete>
            <fileset dir="${outputDir}" includes="**/*"/>
            <fileset dir="${distDir}" includes="**/*"/>
        </delete>
    </target>

    <!-- Compiles the sources -->
    <target name="compile" depends="clean">
        <javac includeantruntime="false"
               srcdir="${sourceDir}"
               destdir="${outputDir}"
               fork="yes"
               executable="${javaHome}/../bin/javac"
               source="1.8"
               debug="on">
        </javac>
    </target>

</project>

Images in package folder 包文件夹中的图像

The images in your package folder need to be renamed. 您的包文件夹中的图像需要重命名。 The icon file need to be exactly (case-sensitive) named as the property application.title in your maven pom. 图标文件必须准确(区分大小写)命名为Maven pom中的属性application.title。 The second file is the setup icon, it need the exact application title as first part and -setup-icon.bmp the last part. 第二个文件是安装程序图标,它的第一部分需要确切的应用程序标题,最后一部分需要-setup-icon.bmp。 It needs to be a bmp. 它必须是bmp。 Sizes mentioned above. 上面提到的尺寸。

图标命名

My images looks like that: 我的图像如下所示:

IconFiles

Run configuration 运行配置

The only thing you now need is to run the scripts to deploy it. 您现在唯一需要的是运行脚本进行部署。 For this you need a special run configuration like showing in the next screen: 为此,您需要一个特殊的运行配置,例如在下一个屏幕中显示:

运行配置

App 应用程式

After you have configured the run, run it and you will get the app. 配置运行后,运行它,您将获得应用程序。 My App is nothing special only the default Hello World example and it looks like that: 我的应用程序没有什么特别之处,仅是默认的Hello World示例,它看起来像这样:

应用程式

Path to exe installer exe安装程序的路径

In your project root is a folder target->dist->bundles, there you get your new Setup.exe 在项目根目录中有一个文件夹target-> dist-> bundles,在这里您将获得新的Setup.exe

路径执行

Installer with icon 带图标的安装程序

Finally you got it. 终于明白了。

安装程序

Target structure 目标结构

The target folder contains a non valid jar from the maven run, but it doesn't matter. 目标文件夹包含来自Maven运行的无效jar,但这并不重要。 You only should know, that if you only want the jar to start by double click, you need to choose the one in the dist folder. 您只应该知道,如果只想通过双击启动jar,则需要在dist文件夹中选择一个。 The jar in the dist folder is essential, because the whole process of creating an installer relies on this jar. dist文件夹中的jar是必不可少的,因为创建安装程序的整个过程都依赖于此jar。 Now you be also able to put a *.iss file in your package windows folder to customize more parts of the creation process, like a license file etc. For doing this, have a look here at the documention of Inno Setup. 现在,您还可以在包的Windows文件夹中放置* .iss文件,以自定义创建过程的更多部分,例如许可证文件等。为此,请在此处查看Inno Setup的文档

目标结构

For folks who are already using Maven to build a jar, building a native app and including an icon is easy with the javafx-maven-plugin . 对于已经在使用Maven构建jar的人来说,使用javafx-maven-plugin可以轻松构建本机应用程序并包含图标。 (I found it via this answer .) (我通过此答案找到了它。)

The plugin developers have provided a nice little auto-configuration script . 插件开发人员提供了一个不错的自动配置脚本 I had to add a <vendor> key, but then everything worked smoothly. 我必须添加一个<vendor>密钥,但是随后一切正常。

Once you have that working, all you have to do to get a custom icon is create a correctly-formatted file, give it exactly the same name as the native app, and drop it in the correct folder for the given system: 工作完成后,获取自定义图标所需要做的就是创建一个格式正确的文件,为其提供与本机应用程序完全相同的名称,然后将其放入给定系统的正确文件夹中:

  • Windows: put some ICO-file at src/main/deploy/package/windows/{appname}.ico, where {appname} is the configured appname of your application Windows:将一些ICO文件放在src / main / deploy / package / windows / {appname} .ico,其中{appname}是应用程序的已配置应用程序名称
  • Mac OS(X): put some ICNS-file at src/main/deploy/package/macosx/{appname}.icns, where {appname} is the configured appname of your application Mac OS(X):将一些ICNS文件放在src / main / deploy / package / macosx / {appname} .icns中,其中{appname}是应用程序的已配置应用程序名称
  • Linux: put some PNG-file at src/main/deploy/package/linux/{appname}.png, where {appname} is the configured appname of your application Linux:在src / main / deploy / package / linux / {appname} .png中放置一些PNG文件,其中{appname}是应用程序的已配置应用程序名称

(The text above was copied from this issue .) (以上文本是从本期复制而来的。)

I've tested this on both Windows and Mac, and it works in both cases. 我已经在Windows和Mac上对此进行了测试,并且在两种情况下都可以使用。

Have you considered using launch4j ? 您是否考虑过使用launch4j I have used it to create my exe files and it works flawlessly and allows you to set the icon. 我用它来创建我的exe文件,它可以完美运行,并允许您设置图标。 I use it coupled with izpack . 我将它与izpack结合使用。

you neeed put the package folder in your root project. 您需要将package文件夹放在根项目中。 The output from console indicate the correct path. 控制台的输出指示正确的路径。 I know this Is old question but can help someone else. 我知道这是个老问题,但可以帮助其他人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Eclipse中创建JavaFX自包含应用程序(使用自定义JDK) - Create JavaFX self-contained application (with custom JDK) in Eclipse JavaFX:将参数传递给自包含应用程序不起作用 - JavaFX: passing Arguments to a Self-Contained Application does not work 如何将动态JVM命令行标志传递给自包含的JavaFX应用程序? - How can dynamic JVM command line flags be passed to a self-contained JavaFX application? 部署 JavaFX 应用程序、创建 JAR 和自包含应用程序以及本机安装程序的最佳方式是什么 - What is the best way to deploy JavaFX application, create JAR and self-contained applications and native installers 如何在不使用 Maven/Gradle/IDE 的情况下部署自包含的 JavaFX 应用程序? - How to deploy a self-contained JavaFX application without using Maven/Gradle/IDEs? 如何使用捆绑在JavaFX 2自包含应用程序中的JRE在Mac OS X上启动可运行的JAR? - How to use the JRE bundled in a JavaFX 2 self-contained application to start a runnable JAR on Mac OS X? 自包含的Javafx应用程序无法在ubuntu中运行:GLIBCXX_3.4.21的问题 - self-contained javafx application fail to run in ubuntu : issue with GLIBCXX_3.4.21 在 Eclipse 中设置 JavaFX 自包含构建时遇到问题 - Trouble setting up a JavaFX self-contained build in Eclipse JavaFX自包含的应用程序缺少密码加密服务吗? - JavaFX self-contained apps are missing the Cipher cryptographic service? 提供启动MySQL的java应用程序(自包含应用程序) - Deliver a java application that starts MySQL (self-contained app)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM