在自包含JavaFX应用程序中包含图标 [英] Include icon in Self-Contained JavaFX application

查看:192
本文介绍了在自包含JavaFX应用程序中包含图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在与这个战斗超过一天,并在SO和其他地方阅读了很多帖子,但我仍然遇到问题。



我需要将我的应用程序图标包含在一个独立的JavaFX应用程序包中。我正在使用JDK 1.8.0_45及其包含的JavaFX包。我正在使用Maven来构建.exe并且一切都很好,除了我不能得到我的图标。



这是我的pom.xml:

 <?xml version =1.0encoding =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>

<先决条件>
< 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>
<! - 将您应用的所有依赖项复制到目标文件夹 - >
< 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>
<! - 列出所有依赖项 - >

< / JavaFX-Class-Path>
<! - jfxrt.jar的artifactId(name)...请参阅依赖系统范围 - >
< 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>

<! - 定义部署ANT任务 - >
< taskdef name =jfxdeployclassname =com.sun.javafx.tools.ant.DeployFXTask
classpathref =mypath/>
<! - 定义JarSign ANT任务 - >
< taskdef name =jfxsignjarclassname =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 Dashboardvendor =My Company,Inc。/>
< application name =DRMDashboardmainClass =com.mycompany.client.HelloWorldversion =2.0/>
< resources>
< fileset dir =$ {project.build.directory}includes =*。jar/>
<! - includes =*。jar/> - >
< / resources>
<! - 设置你的jvm args - >
< platform javafx =$ {javafx.version} +>
< jvmarg value = - Xms512m/>
< jvmarg value = - Xmx1024m/>
< / platform>
< preferences install =falsemenu =trueshortcut =true/>
< / jfxdeploy>
<! - 你需要自己生成一个密钥 - >
< jfxsignjar destdir =$ {project.build.directory} / deploy
keyStore =c:/Users/me/DRMDashboard.ksstorePass =****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>

编辑1:以下是我的文件浏览器的屏幕截图:



编辑2:以下是扩展目标文件夹的屏幕截图:



当我使用verbose标志执行构建时,我收到以下消息:

  main:
没有基础JDK。包将使用系统JRE。
使用默认包资源[application icon](将package / windows / DRMDashboard.ico添加到类路径中进行自定义)
图标文件名:C:\ Users \ jernst \ AppData \ Local \Temp\fxbundler8622978628378929412\windows\DRMDashboard.ico
可执行文件名:C:\ Users \ jernst \ AppData \ Local \Temp \ fxbundler8622978628378929412 \ images'\\ war-exe .image\DRMDashboard\DRMDashboard.exe
配置文件保存到C:\ Users \ jernst \ AppData \ Local \Temp \ fxbundler8622978628378929412 \ windows。使用它们来自定义包。
使用默认包资源[Inno安装项目文件](将包/ windows / DRMDashboard.iss添加到要自定义的类路径)
使用默认包资源[安装对话框图标](添加包/ windows / DRMDashboard -setup-icon.bmp到要自定义的类路径)
使用默认包资源[在填充应用程序映像后运行脚本](将package / windows / DRMDashboard-post-image.wsf添加到类路径以自定义)

我已尝试使用环境变量指向JDK的顶级目录(例如C:\Program Files\Java \ jdk1.8.0_45)

  • 你有



    pom.xml



    执行正确部署还需要更多属性。正如您在antrun插件部分中所看到的,您需要在调用构建文件之前重新分配ant环境的属性。属性自动设置为被调用的构建文件。 Normaly Intellij Idea将在项目根目录中为您创建pom.xml。

     <?xml version =1.0编码= UTF-8 >?; 
    < project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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>星球大战< / 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_classpathrefid =maven.compile.classpath/>
    < property name =outputDirvalue =$ {project.build.outputDirectory}/>
    < property name =sourceDirvalue =$ {project.build.sourceDirectory}/>
    < property name =distDirvalue =$ {project.build.outputDirectory} /../ dist/>
    < property name =javaHomevalue =$ {java.home}/>
    < property name =versionNovalue =$ {project.version}/>
    < property name =mainClassvalue =$ {mainClass}/>
    < property name =appNamevalue =$ {application.title}/>
    < property name =appTitlevalue =$ {application.title}/>
    < property name =appVendorvalue =$ {project.organization.name}/>
    < property name =appCopyrightvalue =$ {copyright}/>
    < property name =appMenuGroupvalue =$ {project.organization.name}/>
    < ant antfile =$ {basedir} /build.xmltarget =default/>
    < / target>
    < / configuration>
    < goals>
    < goal> run< / goal>
    < / goals>
    < / execution>
    < / executions>
    < / plugin>
    < / plugins>
    < / build>

    < / project>



    build.xml



    我是试图使它与loosley耦合,所以通常没有必要改变该文件中的任何内容。仅当您想要签名或特殊行为等时.build.xml文件应保存在项目根目录中。

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

    < project name =Appdefault =defaultbasedir =。
    xmlns:fx =javafx:com.sun.javafx.tools.ant>


    < target name =defaultdepends =clean,compile>

    <! - 定义类路径 - >
    < path id =cp>
    < filelist>
    < file name =$ {javaHome} /../ lib / ant-javafx.jar/>
    < file name =$ {basedir}/>
    < / filelist>
    < / path>

    <! - 通过引用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}
    版本= $ {的versionNo}/>


    <! - 定义应用程序所需的资源 - >
    < fx:resources id =appRes>
    < fx:fileset dir =$ {distDir}includes =$ {appName} - $ {versionNo} .jar/>
    < / fx:resources>

    <! - 创建一个jar文件 - >
    < fx:jar destfile =$ {distDir} / $ {appName} - $ {versionNo} .jar>
    < fx:application refid =appId/>
    < fx:resources refid =appRes/>
    < fileset dir =$ {outputDir}/>
    < / fx:jar>

    将FX:部署宽度= 300 HEIGHT = 250
    OUTDIR = $ {DISTDIR} embedJNLP = 真
    OUTFILE =$ {APPNAME } - $ {versionNo}
    nativebundles =exeverbose =true>

    <! - 定义为ex。 min javafx version - >
    <! - < fx:platform /> - >

    <! - 定义应用程序和设置首选项 - >
    < fx:preferences shortcut =trueinstall =truemenu =true/>

    <! - 定义应用程序部分 - >
    < fx:application refId =appId/>

    <! - 定义所需资源 - >
    < fx:resources refid =appRes/>

    <! - 定义应用程序信息详细信息 - >
    < fx:info title =$ {appTitle}
    vendor =$ {appVendor}
    copyright =$ {appCopyright}/>

    <! - 仅针对特殊平台的一些捆绑参数 - >
    < fx:bundleArgument arg =win.menuGroupvalue =$ {appMenuGroup}/>
    < / fx:deploy>

    < / target>

    <! - 删除先前运行的文件夹 - >
    < target name =clean>
    < mkdir dir =$ {outputDir}/>
    < mkdir dir =$ {distDir}/>

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

    <! - 编译来源 - >
    < target name =compiledepends =clean>
    将javac的includeantruntime = 假
    SRCDIR = $ {sourceDir}
    DESTDIR = $ {outputDir} $ B $乙叉= 是
    可执行=$ {javaHome} /../ bin / javac
    source =1.8
    debug =on>
    < / javac>
    < / target>

    < / project>



    包裹文件夹中的图像



    图像在您的包文件夹中需要重命名。图标文件需要完全(区分大小写),在maven pom中命名为属性application.title。第二个文件是设置图标,它需要确切的应用程序标题作为第一部分和-setup-icon.bmp最后一部分。它需要是一个bmp。上面提到的尺寸。





    我的图片看起来像这样:





    运行配置



    您现在唯一需要的是运行脚本来部署它。 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:





    Path to exe installer



    In your project root is a folder target->dist->bundles, there you get your new 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. 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. The jar in the dist folder is essential, because the whole process of creating an installer relies on this 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


    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.

    I need to include my application icon in a self-contained JavaFX application package. I'm using JDK 1.8.0_45 and its included JavaFX package. I'm using Maven to build the .exe and it all works great except I can't get my icon included.

    Here is my 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:

    EDIT 2: Here's a screenshot of the expanded target folder:

    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

    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. Now my only problem is that the dialog box icon still uses the generic java coffee cup:

    Here's my current 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. That line tells the inno installer to use the icon. The last piece of the puzzle is how to make inno use the bmp for the dialog box image. 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)
    • You have a JDK installed at least in version 1.8.0 (javafx included)
    • 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)
    • You have Inno Setup at least in version 5.5.5 installed (prefered the unicode version)
    • You already have a icon file (256 x 256px), prefered a multisize one. I recommend to visit this site: http://icoconvert.com/
    • You already have a bmp file (48 x 48 px) for the setup installer as setup icon

    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.

    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. 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.

    <?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

    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.

    <?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. The second file is the setup icon, it need the exact application title as first part and -setup-icon.bmp the last part. It needs to be a bmp. Sizes mentioned above.

    My images looks like that:

    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:

    Path to exe installer

    In your project root is a folder target->dist->bundles, there you get your new 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. 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. The jar in the dist folder is essential, because the whole process of creating an installer relies on this 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.

    这篇关于在自包含JavaFX应用程序中包含图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆