JavaFx:如何在创建exe时捆绑外部jar

时间:2015-07-30 05:31:24

标签: java javafx derby

我是Javafx的初学者,我创建了一个桌面应用程序,我在我的应用程序中使用 derby.jar datepicker.jar 文件netbeans推出工作正常。但是当我创建它的 exe 文件包时, exe 在启动时显示以下错误。

JavaFX Luncher错误

请有人指导我。

虽然我在 build.xml

中使用了以下脚本
       <target name="-post-jfx-deploy">
     <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" 
              nativeBundles="all"
              outdir="${basedir}/${dist.dir}" outfile="${application.title}">
      <fx:application name="${application.title}" 
                      mainClass="${javafx.main.class}"/>
      <fx:resources>
          <fx:fileset dir="${basedir}/${dist.dir}"
                      includes="*.jar"/>


      </fx:resources>
      <fx:info title="${application.title}" 
               vendor="${application.vendor}"/>
    </fx:deploy>          
 </target>

1 个答案:

答案 0 :(得分:1)

这是我正在使用的支持JavaFX的Ant构建文件,使用Proguard进行模糊处理,并发布本机安装程序:

<?xml version="1.0" encoding="UTF-8"?>
<project name="My App" default="default" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">

    <property name="jdk.home" value="C:\Program Files\Java\jdk1.8.0_51"/>
    <property name="source.dir" value="src"/>
    <property name="out.dir" value="build"/>
    <property name="lib.dir" value="libs"/>
    <property name="out.dir.classes" value="${out.dir}/classes" />
    <property name="out.dir.dist" value="${out.dir}/dist"/>
    <property name="app.jar.name.notReady" value="MyApp-NotReady.jar"/>
    <property name="app.jar.name" value="MyApp.jar"/>
    <property name="javafx.main.class" value="eng.fouad.AppEntryPoint"/>
    <property name="javafx.run.width" value="600"/>
    <property name="javafx.run.height" value="400"/>
    <property name="application.title" value="My App"/>
    <property name="application.vendor" value="Company Name"/>

    <path id="classpath">
        <fileset dir="${jdk.home}/jre/lib" includes="**/*.jar"/>
        <fileset dir="${jdk.home}/jre/lib/ext" includes="**/*.jar"/>
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

    <target name="default">
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                 uri="javafx:com.sun.javafx.tools.ant"
                 classpath="${jdk.home}/lib/ant-javafx.jar"/>
    </target>

    <target name="clean">
        <delete dir="${out.dir}"/>
    </target>

    <target name="init" depends="clean">
        <mkdir dir="${out.dir}"/>
        <mkdir dir="${out.dir.classes}"/>
        <mkdir dir="${out.dir.dist}"/>
    </target>

    <target name="compile" depends="default, init">
        <javac includeantruntime="false" srcdir="${source.dir}" destdir="${out.dir}/classes" encoding="UTF-8">
            <compilerarg value="-XDignore.symbol.file" />
            <classpath>
                <fileset dir="${jdk.home}/jre/lib" includes="**/*.jar"/>
                <fileset dir="${jdk.home}/jre/lib/ext" includes="**/*.jar"/>
                <fileset dir="${lib.dir}" includes="**/*.jar"/>
            </classpath>
        </javac>
        <copy todir="${out.dir}/classes">
            <fileset dir="${source.dir}">
                <include name="**/*.png" />
                <include name="**/*.mp3" />
                <include name="**/*.ttf" />
                <include name="**/*.fxml" />
                <include name="**/*.css" />
                <include name="**/*.properties" />
            </fileset>
        </copy>
        <unzip dest="${out.dir}/classes">
            <fileset dir="${lib.dir}">
                <include name="**/*.jar" />
            </fileset>
        </unzip>
    </target>

    <target name="build" depends="compile">
        <fx:application id="appId" mainClass="${javafx.main.class}"/>

        <fx:jar destfile="${out.dir.dist}/${app.jar.name.notReady}">
            <fx:application refid="appId"/>
            <manifest>
                <attribute name="Main-Class" value="${javafx.main.class}"/>
                <attribute name="Implementation-Vendor" value="Company"/>
                <attribute name="Implementation-Title" value="My App"/>
                <attribute name="Implementation-Version" value="1.0"/>
            </manifest>

            <fileset dir="${out.dir.classes}"/>
        </fx:jar>
    </target>

    <target name="obfuscate" depends="build">
        <taskdef resource="proguard/ant/task.properties"
                 classpath="proguard.jar" />
        <proguard ignorewarnings="true">

            -libraryjars ${java.home}/lib/rt.jar
            -libraryjars ${java.home}/lib/ext/jfxrt.jar
            -injars ${out.dir.dist}/${app.jar.name.notReady}
            -outjars ${out.dir.dist}/${app.jar.name}

            -keepattributes *Annotation*
            -keepattributes Signature
            -keepattributes InnerClasses
            -dontwarn
            -allowaccessmodification
            -dontoptimize

            -keepclasseswithmembers public class * {
            public static void main(java.lang.String[]);
            }

            -keepclassmembers class * {
                @javafx.fxml.FXML *;
            }
        </proguard>

    </target>

    <target name="deploy" depends="obfuscate">
        <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}"
                   nativeBundles="all" verbose="true"
                   outdir="${out.dir.dist}" outfile="${application.title}">
            <fx:preferences id="p1" shortcut="true"/>
            <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
            <fx:resources>
                <fx:fileset dir="${out.dir.dist}" includes="${app.jar.name}"/>
            </fx:resources>
            <fx:info title="${application.title}" vendor="${application.vendor}"/>
        </fx:deploy>
    </target>
</project>