title: Deploying a JavaFX 2 application with referenced jars, using Ant
body: <p>I have written a JavaFx 2 application (using Eclipse on a Windows platform) and now I want to deploy it to a "clickable" jar-file. <em>My application uses resource-code from a separate jar-file  (in Eclipse, this resource code is a separate Project from the JavaFx application project)</em>.</p>
  
  <p>With my Ant build.xml, I have compiled the code for both the application and the resource code and created two jar-files:</p>
  
  <ol>
  <li><strong>fxdemo.jar</strong> - A jar for my JavaFx application code</li>
  <li><strong>guifw.jar</strong> - A jar for the resource code referenced by the JavaFx application.</li>
  </ol>
  
  <p>As a last step (I thought), using the JavaFX Ant tasks, I wanted to bundle these two jar-files to a "clickable" jar that starts my JavaFX application. I tried doing just that with the below extract from my <strong>build.xml</strong>. </p>
  
  <pre><code>&lt;target name="deployFx" depends="fxdemo.jar" description="Releases FxDemo"&gt;
      &lt;taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
                uri="javafx:com.sun.javafx.tools.ant"
                classpath=".:${fxgui.javaHome}\lib\ant-javafx.jar"/&gt;
  
      &lt;copy file="${fxgui.lib_guifw_path}" tofile="delivery/lib/guifw.jar"/&gt;          
  
      &lt;fx:application id="FxDemoGUI" name="Fx Demo GUI" MainClass="com.demo.main.MainGUI"/&gt;
  
      &lt;fx:resources id="jars"&gt;
          &lt;fx:fileset dir="delivery/lib" includes="fxdemo.jar"/&gt;
          &lt;fx:fileset dir="delivery/lib" includes="guifw.jar"/&gt;
      &lt;/fx:resources&gt;
  
      &lt;fx:jar destfile="deploy/fxDemoGui.jar"&gt;
          &lt;!-- Define what to launch  --&gt;
          &lt;fx:application refid="FxDemoGUI"/&gt;
  
          &lt;fx:platform javafx="2.1+"&gt;
              &lt;fx:jvmarg value="-Xms32m"/&gt;
              &lt;fx:jvmarg value="-Xmx32m"/&gt;
              &lt;property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/&gt;
              &lt;property name="user.language" value="en"/&gt;
              &lt;property name="user.country" value="GB"/&gt;
              &lt;property name="CSS_ID" value="NIGHT"/&gt;
          &lt;/fx:platform&gt;
  
          &lt;fx:resources&gt;
              &lt;fx:fileset dir="delivery/lib" includes="fxdemo.jar"/&gt;
              &lt;fx:fileset dir="delivery/lib" includes="guifw.jar"/&gt;
          &lt;/fx:resources&gt;
  
          &lt;manifest&gt;
              &lt;attribute name="Implementation-Vendor" value="${fxgui.vendor}"/&gt;
              &lt;attribute name="Implementation-Title" value="${fxgui.title}"/&gt;
              &lt;attribute name="Implementation-Version" value="1.0"/&gt;
          &lt;/manifest&gt;
  
          &lt;fileset dir="delivery"/&gt;
  
      &lt;/fx:jar&gt;
  </code></pre>
  
  <p>However, afterwards when I try to start the application (by either clicking the jar or starting from command line with <em>java -jar appname.jar</em>) it seems as the application can not find the Main class:</p>
  
  <p><strong>JavaFX Launcher Error</strong> </p>
  
  <p><strong>Unable to find class: com.demo.main.MainGUI</strong></p>
  
  <pre><code>C:\Program Files\Java\jdk1.7.0_09\bin&gt;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)
  </code></pre>
  
  <p>When I studie the created MANIFEST.MF (in the created jar-file) it looks pretty much as what I expected.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>... but then again, it doesn't work so obviously I have done something wrong.</p>
  
  <p>I also tried including the classes-directory (the output folders from each of the two Eclipse/projects) by adding:</p>
  
  <pre><code>&lt;fileset dir="../guifw/classes"/&gt;
  &lt;fileset dir="classes"/&gt;
  </code></pre>
  
  <p>Then, the launcher <em>does</em> find my main class (com.demo.main.MainGUI) but failes to run correctly because it lacks the <strong>-D argument</strong> that I tried to specify with:</p>
  
  <pre><code>&lt;property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/&gt;
  </code></pre>
  
  <p>So, if you have read this far, my questions are:</p>
  
  <ol>
  <li><em>Why can't the launcher find my main class in the referenced jar (fxdemo.jar)?</em></li>
  <li><em>What have I done wrong when it comes to specify my -D arguments to the application?</em></li>
  </ol>
  
  <p>Best regards</p>