Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Deployment 使用Ant部署带有引用JAR的JavaFX2应用程序_Deployment_Ant_Javafx 2_Executable Jar - Fatal编程技术网

Deployment 使用Ant部署带有引用JAR的JavaFX2应用程序

Deployment 使用Ant部署带有引用JAR的JavaFX2应用程序,deployment,ant,javafx-2,executable-jar,Deployment,Ant,Javafx 2,Executable Jar,我已经编写了一个JavaFX2应用程序(在Windows平台上使用Eclipse),现在我想将其部署到一个“可点击”的jar文件中。我的应用程序使用单独jar文件中的资源代码(在Eclipse中,此资源代码是JavaFx应用程序项目中的一个单独项目) 使用Ant build.xml,我编译了应用程序代码和资源代码,并创建了两个jar文件: fxdemo.jar-我的JavaFx应用程序代码的jar guifw.jar-JavaFx应用程序引用的资源代码的jar 最后一步(我想),使用JavaFX

我已经编写了一个JavaFX2应用程序(在Windows平台上使用Eclipse),现在我想将其部署到一个“可点击”的jar文件中。我的应用程序使用单独jar文件中的资源代码(在Eclipse中,此资源代码是JavaFx应用程序项目中的一个单独项目)

使用Ant build.xml,我编译了应用程序代码和资源代码,并创建了两个jar文件:

  • fxdemo.jar-我的JavaFx应用程序代码的jar
  • guifw.jar-JavaFx应用程序引用的资源代码的jar
  • 最后一步(我想),使用JavaFXAnt任务,我想将这两个jar文件捆绑到一个“可点击”的jar中,启动我的JavaFX应用程序。我试着用我的build.xml中的以下摘录来实现这一点

    <target name="deployFx" depends="fxdemo.jar" description="Releases FxDemo">
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
                  uri="javafx:com.sun.javafx.tools.ant"
                  classpath=".:${fxgui.javaHome}\lib\ant-javafx.jar"/>
    
        <copy file="${fxgui.lib_guifw_path}" tofile="delivery/lib/guifw.jar"/>          
    
        <fx:application id="FxDemoGUI" name="Fx Demo GUI" MainClass="com.demo.main.MainGUI"/>
    
        <fx:resources id="jars">
            <fx:fileset dir="delivery/lib" includes="fxdemo.jar"/>
            <fx:fileset dir="delivery/lib" includes="guifw.jar"/>
        </fx:resources>
    
        <fx:jar destfile="deploy/fxDemoGui.jar">
            <!-- Define what to launch  -->
            <fx:application refid="FxDemoGUI"/>
    
            <fx:platform javafx="2.1+">
                <fx:jvmarg value="-Xms32m"/>
                <fx:jvmarg value="-Xmx32m"/>
                <property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/>
                <property name="user.language" value="en"/>
                <property name="user.country" value="GB"/>
                <property name="CSS_ID" value="NIGHT"/>
            </fx:platform>
    
            <fx:resources>
                <fx:fileset dir="delivery/lib" includes="fxdemo.jar"/>
                <fx:fileset dir="delivery/lib" includes="guifw.jar"/>
            </fx:resources>
    
            <manifest>
                <attribute name="Implementation-Vendor" value="${fxgui.vendor}"/>
                <attribute name="Implementation-Title" value="${fxgui.title}"/>
                <attribute name="Implementation-Version" value="1.0"/>
            </manifest>
    
            <fileset dir="delivery"/>
    
        </fx:jar>
    
    当我研究创建的MANIFEST.MF(在创建的jar文件中)时,它看起来与我预期的非常接近

    Manifest-Version: 1.0
    JavaFX-Version: 2.1+
    implementation-vendor: MyVendor
    implementation-title: MyfirstJavaFxDeploy
    implementation-version: 1.0
    JavaFX-Application-Class:com.demo.main.MainGUI
    JavaFX-Class-Path: fxdemo.jar guifw.jar
    Created-By: JavaFXPackager
    Main-Class: com/javafx/main/Main
    
    。。。但话说回来,它不起作用,很明显我做错了什么

    我还尝试通过添加以下内容来包括classes目录(两个Eclipse/project中的每个项目的输出文件夹):

    <fileset dir="../guifw/classes"/>
    <fileset dir="classes"/>
    
    
    
    然后,启动器确实找到了我的主类(com.demo.main.MainGUI),但由于缺少我试图指定的-D参数,因此无法正确运行:

    <property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/>
    
    
    
    因此,如果您已经阅读了本文,我的问题是:

  • 为什么启动器在引用的jar(fxdemo.jar)中找不到我的主类
  • 在为应用程序指定my-D参数时,我做错了什么

  • 最诚挚的问候

    我研究/测试了@Anders-peterson:

    从我所看到的,这是一种解决方法,可以在生成的jar文件(fxDemoGui.jar)中解开任何使用过的jar文件(在我的例子中是guifw.jar&demofx.jar),就像从我的两个Eclipse项目中添加classes文件夹一样(如问题中所述)

    我将示例调整为我的build.xml,并在添加了一点内容后使其正常工作:

    <target name="dist" depends="fxdemo.jar">
    
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
                                  uri="javafx:com.sun.javafx.tools.ant"
                                  classpath=".:${fxgui.javaHome}\lib\ant-javafx.jar"/>
    
        <copy file="${fxgui.lib_guifw_path}" tofile="delivery/lib/guifw.jar"/>
    
        <fx:jar destfile="predeploy/fxDemoGui.jar">
            <!-- ADDITION -> Adds the Launcher's Main class to the resulting jar (com.javafx.main.Main)! -->
            <fx:application id="FxDemoGUI"
                            name="Fx Demo GUI"
                            mainClass="com.demo.main.MainGUI"/>
    
            <fileset dir="delivery"/>
        </fx:jar>
    </target>
    
    
    
    在示例中的dist-目标中,我必须添加:

    <fx:application id="FxDemoGUI"
                    name="Fx Demo GUI"
                    mainClass="com.demo.main.MainGUI"/>
    
    
    
    没有它,生成的jar文件就没有必要的com.javafx.main.main-类,因此无法启动

    因此,这个解决方案为我的问题1提供了一个有用的解决方法


    尽管如此,如果有人能提出一个解决方案,让jar文件在生成的jar/文件中保持完整,我将不胜感激。

    一个可能的修复/解决方案可能是本次讨论的最后一篇文章:下面是一个使用-而不是基于ant的包的解决方案。我不知道这是否正是您想要的,但这是我来的为了解决将JavaFX应用程序编译(并签名!)到单个.JAR中的类似问题,我们提供了一个解决方案。
    <fx:application id="FxDemoGUI"
                    name="Fx Demo GUI"
                    mainClass="com.demo.main.MainGUI"/>