我正在尝试使用Ant为我的JavaFX应用程序生成一个可执行jar,而我的jar和JavaFX Packager生成的jar之间的区别在于后者包含来自com.javafx.main包的类。 如何在我的Ant脚本中告诉我们还要在jar中包含这些类?
答案 0 :(得分:3)
您正在使用的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的类,manifest将把它们作为应用程序的入口点。更多信息: http://docs.oracle.com/javafx/2/deployment/packaging.htm