用ant导出JavaFX项目

时间:2015-06-15 13:25:40

标签: java eclipse ant javafx

我在将JavaFX项目导出为可执行jar文件时出现了一些问题,我正在使用以下ant脚本:

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="A2-Computing-Coursework" default="do-deploy" basedir="."  xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <target name="init-fx-tasks">
        <path id="fxant">
            <filelist>
                <file name="${java.home}\..\lib\ant-javafx.jar"/>
                <file name="${java.home}\lib\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" />

        <copy todir="externalLibs">
            <fileset dir="C:\Users\alexb\Documents\GitHub\A2-Computing-Coursework\resources">
                <filename name="sqlite-jdbc-3.8.10.1.jar"/>
            </fileset>
        </copy>

        <mkdir dir="project" />
        <copy todir="project">
            <fileset dir="C:\Users\alexb\Documents\GitHub\A2-Computing-Coursework">
                <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">
                <include name="sqlite-jdbc-3.8.10.1.jar"/>
            </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="A2-Computing-Coursework.jar"/>
            <fx:fileset dir="dist" includes="libs/*"/>
        </fx:resources>

        <fx:application id="fxApplication"
            name="A2-Computing-Coursework"
            mainClass="net.Bancey.A2COMP2CW.GUI"
        />

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



        <fx:jar destfile="dist/A2-Computing-Coursework.jar">
            <fx:application refid="fxApplication"/>
            <fileset dir="build/classes">
            </fileset>
            <fx:resources refid="appRes"/>

            <manifest>
                <attribute name="Implementation-Vendor" value="Bancey"/>
                <attribute name="Implementation-Title" value="A2-Computing-Coursework"/>
                <attribute name="Implementation-Version" value="1.0.1"/>
                <attribute name="JavaFX-Feature-Proxy" value="None"/>
            </manifest>
        </fx:jar>




    </target>
</project>

它成功构建和导出但是当我尝试运行jar文件时,屏幕上会弹出一个窗口,它会生成我的数据库文件,但随后关闭,我在eclipse中运行我的项目没有问题这让我相信我在jar中缺少引用的库。有谁知道这是否会导致这个问题,以及我如何修改我的ANT脚本?

亲切的问候, 亚历

0 个答案:

没有答案