gpt4 book ai didi

JavaFX 使用 Ant 部署额外文件

转载 作者:行者123 更新时间:2023-12-02 11:40:20 25 4
gpt4 key购买 nike

在我的JavaFX-Project中,我导入了.exe文件:tool.exe

图片1

Ant的帮助下我得到了安装文件:

图片2

我安装了该应用程序。我的目标是将 tool.exe 文件包含在安装文件夹中:

图片3

您能帮我找出需要添加到 Ant 脚本中的哪一行代码吗?

<target name="init-fx-tasks">

<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar" />
<file name="${java.home}\lib\jfxrt.jar" />
</filelist>
</path>

<taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpathref="fxant" />

</target>

<target name="setup-staging-area">

<delete dir="externalLibs" />
<delete dir="project" />
<delete dir="projectRefs" />

<mkdir dir="externalLibs" />
<mkdir dir="project" />
<mkdir dir="projectRefs" />

<copy todir="project">
<fileset dir="C:\Users\name\workspace\project\Test">
<include name="src/**" />
</fileset>
</copy>

</target>

<target name='do-compile'>

<delete dir="build" />

<mkdir dir="build/src" />
<mkdir dir="build/libs" />
<mkdir dir="build/classes" />

<copy todir="build/libs">
<fileset dir="externalLibs">
</fileset>
</copy>

<copy todir="build/src">
<fileset dir="project/src">
<include name="**/*" />
</fileset>
</copy>

<javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="Cp1252">
<classpath>
<fileset dir="build/libs">
<include name="*" />
</fileset>
</classpath>
</javac>

<copy todir="build/classes">
<fileset dir="project/src">
<exclude name="**/*.java" />
</fileset>
</copy>

</target>

<target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">

<delete file="dist" />
<delete file="deploy" />

<mkdir dir="dist" />
<mkdir dir="dist/libs" />

<copy todir="dist/libs">
<fileset dir="externalLibs">
<include name="*" />
</fileset>
</copy>

<fx:resources id="appRes">
<fx:fileset dir="dist" includes="Test.jar" />
<fx:fileset dir="dist" includes="libs/*" />
<fx:fileset dir="build" includes="tools/*" />
</fx:resources>

<fx:application id="fxApplication" name="TEST" mainClass="application.Main" toolkit="fx" />

<mkdir dir="build/classes/META-INF" />

<fx:jar destfile="dist/Test.jar">
<fx:application refid="fxApplication" />
<fileset dir="build/classes">
</fileset>
<fx:resources refid="appRes" />

<manifest>
<attribute name="Implementation-Vendor" value="Software" />
<attribute name="Implementation-Title" value="TEST" />
<attribute name="Implementation-Version" value="1" />
<attribute name="JavaFX-Feature-Proxy" value="None" />
</manifest>
</fx:jar>

<mkdir dir="deploy" />

<fx:deploy embedJNLP="false" extension="false" includeDT="false" offlineAllowed="true" outdir="${basedir}/deploy" outfile="Test" nativeBundles="exe" updatemode="background">

<fx:platform basedir="${java.home}" />
<fx:info title="Test" vendor="Software" />
<fx:application refId="fxApplication" />
<fx:resources refid="appRes" />

</fx:deploy>

</target>

我尝试添加这一行,但没有成功。

<copy todir="project">
<fileset dir="C:\Users\name\workspace\project\Test">
<include name="src/**" />
<include name="tool.exe" />
</fileset>
</copy>

提前致谢

最佳答案

我做到了!

也许对其他人有用。

您需要在dist文件夹中创建resources文件夹。

<mkdir dir="dist" />
<mkdir dir="dist/libs" />
...
<mkdir dir="dist/resources" /> <---------- This line
...

该文件夹会自动复制。

我将文件tool.exe复制到里面。

<copy todir="dist/resources">
<fileset dir="C:\Users\name\workspace\project\Test">
<include name="tool.exe" />
</fileset>
</copy>

并在fx:resources中声明。

<fx:resources id="appRes">
<fx:fileset dir="dist" includes="Test.jar" />
<fx:fileset dir="dist" includes="libs/*" />
...
<fx:fileset dir="dist" includes="resources/**" /> <---------- This line
...
</fx:resources>

非常感谢大家。

关于JavaFX 使用 Ant 部署额外文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48622694/

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