我已经和这件事斗争了一天多,在SO和其他地方读了很多帖子,但我仍然有问题。
我需要在一个自包含的JavaFX应用程序包中包含我的应用程序图标。我使用的是JDK1.8.0_45及其包含的JavaFX包。我正在使用Maven构建.exe,除了我不能包含我的图标外,它都运行得很好。
下面是我的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>
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)
<?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>
使图标出现在标题栏中的是javapackager部署步骤的-bicon=${project.build.directory}/classes/${application.title}.ico
参数。这一行告诉inno安装程序使用图标。最后一个难题是如何使inno使用对话框图像的bmp。以下是日志文件的相关位:
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
您可以看到它在哪里找到我的自定义应用程序图标,但它没有找到自定义设置对话框图标。
<?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>
<?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>
在您的项目根目录中有一个文件夹target->dist->bundles,在这里您可以得到新的setup.exe
你终于明白了。
目标文件夹包含一个来自maven运行的无效jar,但这并不重要。您只需要知道,如果您只想双击jar启动,您需要选择dist文件夹中的一个。dist文件夹中的jar是必不可少的,因为创建安装程序的整个过程都依赖于这个jar。现在,您还可以将一个*.iss文件放在您的package windows文件夹中,以自定义创建过程的更多部分,如许可证文件等。为此,请查看Inno Setup的文档。
按照这里和这里的指示。我使用的是JDK7U9和NetBeans 7.2.1。我所做的是创建相对于我的项目根文件夹的整个路径(C:\users\administrator\desktop\icotest\package\windows\icotest.ico)。我同时尝试了48x48和256x256的大小。下面是我的项目Icotest的树状结构概述: 这就是build.xml的样子:
通过将以下代码片段复制到构建中,我使用netbeans创建了javafx独立应用程序。xml文件 我有x64位版本的jdk环境,所以它创建了只在x64位版本的窗口或操作系统中运行的应用程序。有人能告诉我应该如何改变部署方法,使应用程序在x86位系统上运行。默认情况下netbean占用了64位版本的jdk环境
为了完整起见,我使用Oracle JDK 1.8.0_66 for Mac。
问题内容: 我看过一些在线演示,其中简要提到了Java 9中的独立应用程序,但是我有一个问题需要解决。 使用新的模块系统,现在只允许包含运行应用程序所需的最少代码量。但是,希望运行该应用程序的系统是否仍然需要JRE,或者该程序的基本模块中可以包含某些内容? 我怀疑是后者,因为下载Java最新版本的页面(此处)仍然显示版本8_151。 TL; DR-使用Java 9,是否可以创建一个自包含的可执行文
我是Java开发的新手,这里有一个问题:我生成了web应用程序 ,然后我添加了文件夹和简单的文件。通过命令在my localhost:8080/manager中,我可以看到我的web应用程序,但是我如何在其中添加我的jar文件呢?