签名的Javafx jar工作并执行,但是对javafx jar的jnlp引用找不到对Gui.fxml文件的引用

时间:2015-05-20 22:18:26

标签: java javafx java-web-start embedded-resource jnlp

我正在尝试将javafx应用程序嵌入到项目的网页中。我已经成功导出并执行了这个javafx jar文件。该文件作为可执行jar文件从eclipse导出,然后部署应用程序以创建html,jnlp和我的jar文件的副本。

我签了我的jar,验证它已签名,然后打开chrome中的html文件。 javafx应用程序试图加载,但是出现了这个错误:

    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在代码的主应用程序中指定了这一行:

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);
    }
}

项目设置是:

enter image description here

我还检查了Gui.fxml文件是否位于与jar文件中编译的Main.class相同的文件夹中(将jar切换到zip并检查了zip的内容)和Gui。 fxml都直接位于applications文件夹中。

我意识到jnlp文件找不到.fxml文件,但我不知道如何修复它,因为jar文件已经成功执行了(这意味着jar文件正在查找.fxml文件)。所有通过jnlp文件打开jar的尝试都以上一个错误结束(包括嵌入式和webstart用法)。

这是我的jnlp文件:

<?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>

感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

您需要在实际的Apache服务器(或类似服务器)上进行操作,以便JNLP正确编译,我相信。尝试在服务器上托管此功能,而不是仅从桌面运行该文件,看看是否有帮助。