我试图用Ant为我的JavaFX应用程序生成一个可执行的jar,我的jar和JavaFX包生成的jar之间的区别是,后者包含来自com.javafx.main包的类。如何在Ant脚本中将这些类也包含在jar中呢?
发布于 2013-09-15 18:38:45
您使用的ant文件必须具有部署jar的特殊fx-任务,而不是内置的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的类,清单将将它们作为进入应用程序的入口点。更多信息:http://docs.oracle.com/javafx/2/deployment/packaging.htm
https://stackoverflow.com/questions/18462925
复制相似问题