2013-08-27 34 views
3

我試圖用Ant爲我的JavaFX應用程序生成可執行jar,並且我的jar和由JavaFX Packager生成的jar之間的區別在於後者包含來自com.javafx的類。主包。 如何在我的Ant腳本中告訴將這些類包含在jar中?用Ant腳本部署JavaFX應用程序

回答

3

您使用的ant文件必須具有特殊的fx任務才能部署jar,而不是ant內置的jar任務。下面是生成的JavaFX罐子樣本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"/> 

和項目標籤必須有外匯的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

相關問題