gpt4 book ai didi

java - 我应该在哪里放置安装程序资源(wxs 文件、dmg 脚本、图标)以及在部署自包含应用程序时如何配置 maven antrun

转载 作者:搜寻专家 更新时间:2023-11-01 02:44:28 26 4
gpt4 key购买 nike

我应该将自定义配置的 WIX 安装程序配置文件放在哪里,以及如何使用 antrun 插件在基于 maven 的 java fx 项目中配置 javafx packger 工具?我成功地使用默认包资源制作了基本的 MSI 安装程序,并且工作正常。现在我已经配置了安装程序 WXS 文件,因为底层的 fxpackager 在创建 MSI 时使用了 wix 工具集。

使用这个 Customizing MSI installer还有这个How to set custom icon for javafx native package icon on Windows我设法添加图标。但是部署任务没有选择自定义配置文件,即 WXS

我也看过官方指南http://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html

我的项目结构是这样的

project structure

你可以看到我已经添加到两个位置,即在 java-client/package/windows/ 下。并且我还在 src/main/deploy/package/windows/. 中添加了链接问题中提到的内容。但是这两种方式都不适用于我的 Maven ant 插件。我的心在爆炸。

他们从 Oracle 文档中指出“在恢复为内置资源之前,打包工具会在类路径上查找自定义资源。 Java Packager 有“.” (当前工作目录)默认添加到类路径中。因此,要替换应用程序图标,请将自定义图标复制到运行 javapackager 的目录(通常是项目根目录)中的 ./package/macosx/DemoApp.icns。”

我还尝试将 ${basedir} 添加到 ant class-path 查看我的 pom 构建部分

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<includes>
<include>**/*Test.class</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>create-temp-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:fx="javafx:com.sun.javafx.tools.ant">
<taskdef uri="javafx:com.sun.javafx.tools.ant" resource="com/sun/javafx/tools/ant/antlib.xml"
classpath="maven.plugin.classpath" />

<fx:jar
destfile="${project.build.directory}/${project.build.finalName}-temp">
<fx:application id="fxApp" name="${project.name}"
mainClass="${exec.mainClass}" />
<fx:fileset dir="${project.build.directory}/classes" />
<manifest>
<attribute name="Implementation-Vendor" value="${app.vendor}" />
<attribute name="Implementation-Title" value="${app.name}" />
<attribute name="Implementation-Version" value="1.0" />
</manifest>
</fx:jar>
<attachartifact
file="${project.build.directory}/${project.build.finalName}-temp.jar"
classifier="temp" />
</target>
</configuration>
</execution>
<execution>
<id>create-deployment-bundle</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property name="windows.basedir" value="${basedir}/src/main/deploy/package/windows" />
<property name="mac.basedir" value="${basedir}/package/macosx" />
<property name="my.basedir" value="${basedir}" />
<taskdef uri="javafx:com.sun.javafx.tools.ant" resource="com/sun/javafx/tools/ant/antlib.xml"
classpath="${my.basedir}:${windows.basedir}:${mac.basedir}" />

<fx:deploy nativeBundles="msi" width="600" height="400"
outdir="${dist.dir}" embedJNLP="true" outfile="${project.build.finalName}"
verbose="true">
<fx:application name="${project.build.finalName}"
mainClass="${exec.mainClass}" />
<fx:preferences shortcut="true" menu="true"
install="true" />
<fx:resources>
<fx:fileset dir="${project.build.directory}"
includes="${project.build.finalName}.jar" />
</fx:resources>
<fx:info title="${application.title}" vendor="${application.vendor}"
copyright="${application.copyright}" description="Test built from Java executable jar">
<fx:icon
href="${basedir}/src/main/deploy/package/windows/${project.build.finalName}.ico" />
</fx:info>
<fx:platform javafx="${javafx.version}">
<fx:jvmarg value="-Xms512m" />
<fx:jvmarg value="-Xmx1024m" />
</fx:platform>
<fx:permissions elevated="true" />
</fx:deploy>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ant-javafx</artifactId>
<version>${javafx.version}</version>
<systemPath>${javafx.tools.ant.jar}</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>${javafx.version}</version>
<systemPath>${fx.home}</systemPath>
<scope>system</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
</descriptors>
<finalName>${project.build.finalName}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifestEntries>
<JavaFX-Version>${javafx.version}</JavaFX-Version>
<JavaFX-Application-Class>${exec.mainClass}</JavaFX-Application-Class>
<Main-Class>com/javafx/main/Main</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

你能帮我解决这个问题吗。

最佳答案

经过多次尝试,我终于解决了我的问题,为了帮助其他人,我在这里发布了解决方案。

项目结构应该是这样的

enter image description here

pom.xml 应该是这样的

<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.client</groupId>
<artifactId>JavaClient</artifactId>
<version>5.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>JavaClient</name>

<properties>
<exec.mainClass>com.client.MainApp</exec.mainClass>
<javafx.version>2.2.67</javafx.version>
<fx.home>${java.home}/lib/jfxrt.jar</fx.home>
<javafx.tools.ant.jar>${java.home}/../lib/ant-javafx.jar</javafx.tools.ant.jar>
<javafx-dialogs.jar>${project.basedir}/lib/javafx-dialogs-0.0.1.jar</javafx-dialogs.jar>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dist.dir>${project.build.directory}/deploy</dist.dir>
<base.dir>${project.basedir}</base.dir>
</properties>

<dependencies>
<dependency>
<groupId>org.oracle</groupId>
<artifactId>javafx</artifactId>
<version>${javafx.version}</version>
<systemPath>${fx.home}</systemPath>
<scope>system</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>xmlpull</groupId>
<artifactId>xmlpull</artifactId>
<version>1.1.3.1</version>
</dependency>

<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_min</artifactId>
<version>1.1.4c</version>
</dependency>

<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.7</version>
</dependency>

<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx-dialogs</artifactId>
<version>0.0.1</version>
<scope>system</scope>
<systemPath>${javafx-dialogs.jar}</systemPath>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<includes>
<include>**/*Test.class</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>create-temp-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:fx="javafx:com.sun.javafx.tools.ant">
<taskdef uri="javafx:com.sun.javafx.tools.ant" resource="com/sun/javafx/tools/ant/antlib.xml"
classpath="${project.basedir}:${javafx.tools.ant.jar}:${fx.home}" />

<fx:jar
destfile="${project.build.directory}/${project.build.finalName}-temp">
<fx:application id="fxApp" name="${project.name}"
mainClass="${exec.mainClass}" />
<fx:fileset dir="${project.build.directory}/classes" />
<manifest>
<attribute name="Implementation-Vendor" value="${app.vendor}" />
<attribute name="Implementation-Title" value="${app.name}" />
<attribute name="Implementation-Version" value="1.0" />
</manifest>
</fx:jar>
<attachartifact
file="${project.build.directory}/${project.build.finalName}-temp.jar"
classifier="temp" />
</target>
</configuration>
</execution>
<execution>
<id>create-deployment-bundle</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:fx="javafx:com.sun.javafx.tools.ant">

<taskdef uri="javafx:com.sun.javafx.tools.ant" resource="com/sun/javafx/tools/ant/antlib.xml"
classpath="${project.basedir}:${javafx.tools.ant.jar}:${fx.home}" />

<fx:deploy nativeBundles="all" width="100" height="100"
outdir="${dist.dir}" embedJNLP="true" outfile="${project.build.finalName}"
verbose="true">

<fx:application name="${project.build.finalName}"
mainClass="${exec.mainClass}" />
<fx:resources>
<fx:fileset dir="${project.build.directory}" includes="${project.build.finalName}.jar" />
</fx:resources>
<fx:info title="${project.build.finalName}" vendor="NUAXIS"
description="Test built from Java executable jar" />

<fx:permissions elevated="true" />
</fx:deploy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
</descriptors>
<finalName>${project.build.finalName}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifestEntries>
<JavaFX-Version>${javafx.version}</JavaFX-Version>
<JavaFX-Application-Class>${exec.mainClass}</JavaFX-Application-Class>
<Main-Class>com/javafx/main/Main</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

现在我来解释一下我的错误。仔细查看问题的构建部分。在 ant-run 插件中,当我们进入 fx:deploy 任务时,您会发现我有类路径条目。我搞砸了这很简单的部分。现在看看我的 Pom。类路径现已更新。首先我提到基本目录,然后是 ant-fx-plugin 路径,然后是 jfxrt.jar 路径。 jfxrt 可能不是必需的。在此之后我删除了插件的依赖项部分。这很关键。如果我不删除此部分,那么我的 antrun 插件总是会查看 Maven 提供的依赖项,但不会查看 ant-classpath 中的依赖项。在 ant-classpath 中的顺序非常非常重要。你的 basedir 必须总是在 ant-run.jar 之前。就这样

希望这对面临这个问题的人有所帮助。

关于java - 我应该在哪里放置安装程序资源(wxs 文件、dmg 脚本、图标)以及在部署自包含应用程序时如何配置 maven antrun,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25973919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com