2012-11-28 29 views
7

我已經編寫了一個JavaFx 2應用程序(在Windows平臺上使用Eclipse),現在我想將它部署到「可單擊的」jar文件。 我的應用程序使用來自單獨jar文件的資源代碼(在Eclipse中,此資源代碼是來自JavaFx應用程序項目的獨立項目)使用引用的jar部署JavaFX 2應用程序,使用Ant

用我的Ant build.xml,我編寫的代碼的應用程序和資源都代碼並創建了兩個JAR檔案:

  1. fxdemo.jar - 罈子我的JavaFX應用程序代碼
  2. guifw.jar - JavaFx應用程序引用的資源代碼的jar。

作爲最後一步(我認爲),使用JavaFX Ant任務,我想將這兩個jar文件打包成一個啓動我的JavaFX應用程序的「可點擊」jar。我試圖用我的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> 

但是,後來當我嘗試啓動應用程序(通過點擊罐子或從Java的罐子appname.jar從命令行啓動)它似乎應用程序無法找到主類:

JavaFX的啓動錯誤

無法找到類:com.demo.main.MainGUI

C:\Program Files\Java\jdk1.7.0_09\bin>java -jar C:\MEKMAN\Clearcase_Views\wmarekm_ss_gambau\amb_c2_prototype\javafx\prototypeGUI\deploy\fxDemoGui.jar 
java.lang.ClassNotFoundException: com.demo.main.MainGUI 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:264) 
    at com.javafx.main.Main.getAppClass(Main.java:506) 
    at com.javafx.main.Main.launchApp(Main.java:622) 
    at com.javafx.main.Main.main(Main.java:805) 

當我研究創建的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 

......但是再次,它不工作,所以顯然我做錯了什麼。

我也試過,包括類目錄中加入(從兩個的Eclipse /項目的輸出文件夾):

<fileset dir="../guifw/classes"/> 
<fileset dir="classes"/> 

然後,啓動確實找到我的主類(com.demo .main.MainGUI),但failes因爲它缺乏-D參數我嘗試用指定正確運行:

<property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/> 

所以,如果你已經遠遠此閱讀,我的問題是:

  1. 爲什麼不能在引用的jar(fxdemo.jar)中找到我的主類?
  2. 當我將-D參數指定給應用程序時,我做了什麼錯誤?

此致

+2

這是[DOS批處理文件](http://code.google.com/p/willow-browser/source/browse/package.bat),它使用[javafxpackager工具](http: //docs.oracle.com/javafx/2/deployment/packager.htm) - 不是基於ant的。 – jewelsea

+0

我不知道是否[this](http://stackoverflow.com/questions/24727559/how-can-i-sign-and-deploy-a-javafx-application-into-a-single-jar)是正是你正在尋找的東西,但這是我想出來解決類似的問題,獲得一個JavaFX應用程序編譯(和簽名!)到一個單一的.JAR。 – Will

+0

可能的修復/解決方案可能是本次討論中的最後一篇文章: https://forums.oracle.com/forums/thread.jspa?messageID=10270666 –

回答

2

我研究/測試在交提出的修復(2012-APR-12 3點32)在鏈路從@Anders皮特森:

Link from @Anders Petersson

從我所看到的,這是一個解決方法unbudles任何使用的jar文件(在我的情況下; guifw.jar & demofx.jar)在生成的jar文件(fxDemoGui.jar),就像添加我的兩個Eclipse項目中的類文件夾(如問題中所述)。

我調整的例子我的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 -target,我不得不添加:

<fx:application id="FxDemoGUI" 
       name="Fx Demo GUI" 
       mainClass="com.demo.main.MainGUI"/> 

沒有它,生成的jar文件沒有必要的com.javafx.main.Main -class,因此無法啓動。

因此,該解決方案提出我的問題1)

仍然是一個有用的解決方法,我會很感激,如果有人來了就如何保持的JAR文件的完整產生的內解決JAR /文件。