I wrote a JavaFx 2 application (using Eclipse on a Windows platform), and now I want to deploy it to a clickable jar file. My application uses the resource code from a separate jar file (in Eclipse, this resource code is a separate project from the JavaFx application project).
With my Ant build.xml, I compiled the code for both the application and the resource code and created two jar files:
- fxdemo.jar - jar for my JavaFx application code
- guifw.jar - the jar for the resource code referenced by the JavaFx application.
As a last step (I thought), using JavaFX Ant tasks, I wanted to link these two jar files to the clickable bank that runs my JavaFX application. I tried to do this using the below from my 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"> <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>
However, then when I try to start the application (by clicking on the jar or starting from the command line using java -jar appname.jar), it looks like the application cannot find the main class:
JavaFX startup error
Unable to find class: 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)
When I examine the created MANIFEST.MF file (in the created jar file), it looks something like I expected.
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
... but then again, this does not work, so I did something wrong.
I also tried to include the classes directory (output folders from each of the two Eclipse / projects) by adding:
<fileset dir="../guifw/classes"/> <fileset dir="classes"/>
Then it starts my main class (com.demo.main.MainGUI), but it does not work correctly, because it lacks the -D argument, which I tried to specify with:
<property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/>
So, if you read this far, my questions are:
- Why can't the remote find my main class in the indicated jar (fxdemo.jar)?
- What did I do wrong when I need to specify my -D arguments for the application?
Best wishes