3

I'm trying to generate a executable jar for my JavaFX application with Ant, and the difference between my jar and the one generated by the JavaFX Packager is that the latter include classes from com.javafx.main package. How can I tell in my Ant script to include these classes in the jar as well ?

1 Answer 1

3

The ant file you're using must have the special fx-tasks to deploy the jar, and not the ant built-in jar tasks. Here's a sample ant target for generating a jar with JavaFX:

<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>

Note, that you must have a taskdef defined somewhere in the script:

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

and the project tag must have the fx xmlns reference:

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

The generated jar file should now include the classes from javafx.main and the manifest will include them as an entry point into the application. More info: http://docs.oracle.com/javafx/2/deployment/packaging.htm

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.