我已經編寫了一個JavaFx 2應用程序(在Windows平臺上使用Eclipse),現在我想將它部署到「可單擊的」jar文件。 我的應用程序使用來自單獨jar文件的資源代碼(在Eclipse中,此資源代碼是來自JavaFx應用程序項目的獨立項目)。使用引用的jar部署JavaFX 2應用程序,使用Ant
用我的Ant build.xml,我編寫的代碼的應用程序和資源都代碼並創建了兩個JAR檔案:
- fxdemo.jar - 罈子我的JavaFX應用程序代碼
- 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"/>
所以,如果你已經遠遠此閱讀,我的問題是:
- 爲什麼不能在引用的jar(fxdemo.jar)中找到我的主類?
- 當我將-D參數指定給應用程序時,我做了什麼錯誤?
此致
這是[DOS批處理文件](http://code.google.com/p/willow-browser/source/browse/package.bat),它使用[javafxpackager工具](http: //docs.oracle.com/javafx/2/deployment/packager.htm) - 不是基於ant的。 – jewelsea
我不知道是否[this](http://stackoverflow.com/questions/24727559/how-can-i-sign-and-deploy-a-javafx-application-into-a-single-jar)是正是你正在尋找的東西,但這是我想出來解決類似的問題,獲得一個JavaFX應用程序編譯(和簽名!)到一個單一的.JAR。 – Will
可能的修復/解決方案可能是本次討論中的最後一篇文章: https://forums.oracle.com/forums/thread.jspa?messageID=10270666 –