gpt4 book ai didi

ant - 使用 Ant 脚本部署 JavaFX 应用程序

转载 作者:行者123 更新时间:2023-12-02 00:05:49 26 4
gpt4 key购买 nike

我正在尝试使用 Ant 为我的 JavaFX 应用程序生成一个可执行 jar,我的 jar 和 JavaFX Packager 生成的 jar 之间的区别在于后者包含来自 com.javafx.main 包的类。我如何在我的 Ant 脚本中告诉我将这些类也包含在 jar 中?

最佳答案

您使用的 ant 文件必须有特殊的 fx-tasks 来部署 jar,而不是 ant 内置的 jar 任务。下面是使用 JavaFX 生成 jar 的示例 ant 目标:

<target name="jar" depends="compile">
<echo>Creating the main jar file</echo>
<mkdir dir="${distro.dir}" />
<fx:jar destfile="${distro.dir}/main.jar" verbose="true">
<fx:platform javafx="2.1+" j2se="7.0"/>
<fx:application mainClass="${main.class}"/>

<!-- What to include into result jar file?
Everything in the build tree-->
<fileset dir="${classes.dir}"/>

<!-- Define what auxilary resources are needed
These files will go into the manifest file,
where the classpath is defined -->
<fx:resources>
<fx:fileset dir="${distro.dir}" includes="main.jar"/>
<fx:fileset dir="." includes="${lib.dir}/**" type="jar"/>
<fx:fileset dir="." includes="."/>
</fx:resources>

<!-- Make some updates to the Manifest file -->
<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>
</target>

请注意,您必须在脚本的某处定义一个 taskdef:

<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
uri="javafx:com.sun.javafx.tools.ant"
classpath="${javafx.sdk.path}/lib/ant-javafx.jar"/>

并且项目标签必须有 fx xmlns 引用:

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

生成的 jar 文件现在应该包括来自 javafx.main 的类,并且 list 将包括它们作为应用程序的入口点。更多信息: http://docs.oracle.com/javafx/2/deployment/packaging.htm

关于ant - 使用 Ant 脚本部署 JavaFX 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18462925/

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