Search code examples
javajavafxjava-web-startembedded-resourcejnlp

signed Javafx jar works and executes, but jnlp reference to javafx jar can't find reference to Gui.fxml file


I'm trying to embed a javafx application into a webpage for a project. I have successfully exported and executed this javafx jar file. The file was exported from eclipse as an executable jar file and then deployed the application to create an html, jnlp, and a copy of my jar file.

I signed my jar, verified it was signed, and then opened the html file in chrome. The javafx application attempted to load, but came up with this error:

    java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at application.Main.start(Main.java:19)
    at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$45/5729401.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$44/8383735.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
    at com.sun.glass.ui.win.WinApplication$$Lambda$34/14272056.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.NullPointerException: Location is required.
    at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$45/5729401.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$44/8383735.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
    at com.sun.glass.ui.win.WinApplication$$Lambda$34/14272056.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at application.Main.start(Main.java:19)
    ... 11 more
CacheEntry[file:/C:/Users/tso5912/Desktop/WebDriverEmbed/webDriverDeploy/webdriverjar2.jar]: updateAvailable=true,lastModified=Fri May 22 10:21:49 CDT 2015,length=107020288

Main.java:19 specifies this line in the Main application of code:

root = FXMLLoader.load(getClass().getResource("Gui.fxml"));

package application;

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application
{
    @Override
    public void start(Stage primaryStage)
    {
        Parent root;
        try
        {
            root = FXMLLoader.load(this.getClass().getResource("Gui.fxml"));
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return;
        }

        Scene scene = new Scene(root);
        scene.getStylesheets().add(this.getClass().getResource("application.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.sizeToScene();
        primaryStage.show();
        primaryStage.setResizable(true);
        primaryStage.setTitle("WebDriver");

    }

    public static void main(String[] args)
    {
        launch(args);
    }
}

Project setup is:

enter image description here

I also checked to see if the Gui.fxml file was located in the same folder as the Main.class that was compiled within the jar file (switched the jar to a zip and inspected the contents of the zip) and Gui.fxml were both directly inside of the applications folder.

I realize that the jnlp file can't find the .fxml file, but I have no idea how to go about fixing it since the jar file is successfully executing on its own already (which means that the jar file is finding the .fxml file). All attempts to open the jar via the jnlp file ends in the previous error (including embedded and webstart usage).

This is my jnlp file:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="WebDriver.jnlp">
  <information>
    <title>Sample JavaFX Application</title>
    <vendor>Unknown vendor</vendor>
    <description>Sample JavaFX 2.0 application.</description>
    <offline-allowed/>
  </information>
  <resources>
    <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="webdriverjar.jar" size="31252632" download="eager" />
  </resources>
  <jfx:javafx-desc  width="200" height="200" main-class="application.Main"  name="WebDriver" />
  <update check="background"/>
</jnlp>

Any help is appreciated.


Solution

  • You need to have your ear up on an actual Apache server (or the like) for the JNLP to compile correctly I believe. Try hosting this on a server instead of just running the file from your desktop and see if that helps.