有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JavaFX应用程序:未找到FXML文件

我将我的应用程序打包为JAR文件。运行java -jar myapp.jar效果很好。我想在浏览器中运行这个应用程序,所以我使用javapackage命令创建了JNLP和HTML文件

我已将我的file://URL列为白名单,启用了用于调试输出的控制台,下面是我看到的:

FXML resource = null
load fxml
java.lang.IllegalStateException: Location is not set.
   at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2438)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2413)
   :

相应的代码是:

public class Main extends Application
{
    @Override
    public void start(Stage stage) {
        try {
            System.out.println("FXML resource = " + getClass().getResource("Main.fxml"));
            FXMLLoader fxml_loader = new FXMLLoader(getClass().getResource("Main.fxml"));
            Controller controller = new Controller(stage);
            fxml_loader.setController(controller);
            System.out.println("load fxml");
            Parent root = fxml_loader.load(); 
            :

我已经验证了Main.xml在jar文件中的位置和名称是否正确(请记住,从java运行jar文件是有效的)

为什么在使用webstart运行应用程序时,Main.fxml文件不可见?(javaws myapp.jnlp产生相同的错误)

我是遗漏了什么还是JavaFX&;JNLP

软件:Java 8 u51,Linux Centos 6 64位

更新

我已经签署了我的jar文件,在我的清单中添加了Permissions: sandboxCodebase: *,在我的清单中添加了<security><all-permissions/></security>。jnlp,将控制面板设置设置为尽可能允许,将我的URL(file:/)列入白名单无效。由于“安全原因”,我的应用被阻止。这绝非令人沮丧


共 (1) 个答案

  1. # 1 楼答案

    可能是你的jar文件没有签名吗

    By default web applications run in the sandbox. To request elevated permissions, use the tag. Note that in order for permissions to be granted, application JAR files must be signed, and the user must trust the security certificate used for signing. If the application requests elevated permissions but requirements for the user granting permissions are not met, then the application will fail to launch.

    Before adding code to sign your application, ensure that signing is needed, because it carries a cost of overhead to perform validation and often causes additional dialog boxes to be shown to the end user on application startup. See Section 3.2.4, "Run in Sandbox Unless Signed and Trusted" to find out when an application needs elevated permissions.

    http://docs.oracle.com/javafx/2/deployment/packaging.htm#BABJGFB

    也请查看https://docs.oracle.com/javase/tutorial/deployment/jar/signindex.html