使用javaFX创建可执行应用程序(.exe)

时间:2015-04-07 15:08:06

标签: java ant javafx

我使用JavaFX创建了一个简单的应用程序,我想生成一个可执行文件(.exe),所以这是我的build.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
    <project name="Test JavaFX" default="do-deploy" basedir="."  xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <target name="init-fx-tasks">
        <path id="fxant">
            <filelist>
                <file name="C:\Program Files (x86)\Java\jdk1.8.0_20\lib\ant-javafx.jar"/>
                <file name="C:\Program Files (x86)\Java\jre1.8.0_25\lib\ext\jfxrt.jar"/>
            </filelist>
        </path>

        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
            uri="javafx:com.sun.javafx.tools.ant"
            classpathref="fxant"/>
    </target>
    <target name="setup-staging-area">
        <delete dir="externalLibs" />
        <delete dir="project" />
        <delete dir="projectRefs" />

        <mkdir dir="externalLibs" />


        <mkdir dir="project" />
        <copy todir="project">
            <fileset dir="C:\Users\admin\Documents\workspace luna release 1a(4.4.1)\Test JavaFX">
                <include name="src/**" />
            </fileset>
        </copy>

        <mkdir dir="projectRefs" />
    </target>
    <target name='do-compile'>
        <delete dir="build" />
        <mkdir dir="build/src" />
        <mkdir dir="build/libs" />
        <mkdir dir="build/classes" />

        <!-- Copy project-libs references -->
        <copy todir="build/libs">
            <fileset dir="externalLibs">
            </fileset>
        </copy>

        <!-- Copy project references -->

        <!-- Copy project sources itself -->
        <copy todir="build/src">
            <fileset dir="project/src">
                <include name="**/*"/>
            </fileset>
        </copy>

        <javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="Cp1252">
            <classpath>
                <fileset dir="build/libs">
                    <include name="*"/>
                </fileset>
            </classpath>
        </javac>

        <!-- Copy over none Java-Files -->
        <copy todir="build/classes">
        <fileset dir="project/src">
            <exclude name="**/*.java"/>
        </fileset>
        </copy>


    </target>
    <target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">
        <delete file="dist"/>
        <delete file="deploy" />

        <mkdir dir="dist" />
        <mkdir dir="dist/libs" />

        <copy todir="dist/libs">
            <fileset dir="externalLibs">
                <include name="*" />
            </fileset>
        </copy>


        <fx:resources id="appRes">
            <fx:fileset dir="dist" includes="Test JavaFX.jar"/>
            <fx:fileset dir="dist" includes="libs/*"/>
        </fx:resources>

        <fx:application id="fxApplication"
            name="PersonDetails"
            mainClass="application.Main"
        />

        <mkdir dir="build/classes/META-INF" />



        <fx:jar destfile="dist/Test JavaFX.jar">
            <fx:application refid="fxApplication"/>
            <fileset dir="build/classes">
            </fileset>
            <fx:resources refid="appRes"/>

            <manifest>
                <attribute name="Implementation-Vendor" value="Slimen"/>
                <attribute name="Implementation-Title" value="PersonDetails"/>
                <attribute name="Implementation-Version" value="1.0.0"/>
                <attribute name="JavaFX-Feature-Proxy" value="None"/>
            </manifest>
        </fx:jar>


        <mkdir dir="deploy" />
        <!-- Need to use ${basedir} because somehow the ant task is calculating the directory differently -->
        <fx:deploy
            embedJNLP="false"
            extension="false"
            includeDT="false"
            offlineAllowed="true"
            outdir="${basedir}/deploy"
            outfile="Test JavaFX" nativeBundles="exe"
            updatemode="background" >

            <fx:platform basedir="C:\Program Files (x86)\Java\jdk1.8.0_20"/>
            <fx:info title="Test JavaFX" vendor="Slimen"/>

            <fx:application refId="fxApplication"/>
            <fx:resources refid="appRes"/>
        </fx:deploy>


    </target>
</project>

当我以Ant Build运行此文件时,一切顺利,我收到BUILD SUCCESSFUL消息,但似乎没有生成.exe文件并显示此消息:
enter image description here 他给了我一个建议Make sure to use fx:jar task to create main application jar.但我已经在build.xml文件中有了这个配置:

<fx:jar destfile="dist/Test JavaFX.jar">
            <fx:application refid="fxApplication"/>
            <fileset dir="build/classes">
            </fileset>
            <fx:resources refid="appRes"/>

            <manifest>
                <attribute name="Implementation-Vendor" value="Slimen"/>
                <attribute name="Implementation-Title" value="PersonDetails"/>
                <attribute name="Implementation-Version" value="1.0.0"/>
                <attribute name="JavaFX-Feature-Proxy" value="None"/>
            </manifest>
        </fx:jar>

我缺少什么?
修改
创建jar文件:
enter image description here

0 个答案:

没有答案