Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我使用javafx14应用程序的eclipse导出了一个可运行的jar,但无法运行该应用程序_Java_Eclipse_Javafx_Fxml_Executable Jar - Fatal编程技术网

我使用javafx14应用程序的eclipse导出了一个可运行的jar,但无法运行该应用程序

我使用javafx14应用程序的eclipse导出了一个可运行的jar,但无法运行该应用程序,java,eclipse,javafx,fxml,executable-jar,Java,Eclipse,Javafx,Fxml,Executable Jar,我有一个问题,我目前正在eclipse上进行一个javafx14项目,该项目几乎完成了 因此,我将应用程序导出为可运行的jar。但当我尝试通过键入来使用控制台运行它时 java --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml -jar app.jar 或 或者其他什么。 它给了我以下信息 Error occurred during initialization of boot layer java.lan

我有一个问题,我目前正在eclipse上进行一个javafx14项目,该项目几乎完成了

因此,我将应用程序导出为可运行的jar。但当我尝试通过键入来使用控制台运行它时

java --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml -jar app.jar

或者其他什么。 它给了我以下信息

Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
或者这个:

Error: JavaFX runtime components are missing, and are required to run this application

请帮忙。提前感谢

您必须指定javafx控件的完整路径。我建议使用gradle或maven作为选择器。使用gradle,你可以创建一个bat文件来运行你的应用程序并处理其余的事情

build.gradle

plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.jlink' version '2.17.2'
}

javafx {
    version = "11.0.2"
    modules = [ 'javafx.controls' ] // you can add 'javafx.fxml', ...
}

group 'flpe'
version '1.0-SNAPSHOT'

// Use Java 13 only if you use Gradle 6+
// The JDK folder must be added to the environment variable JAVA_HOME 
 (https://www.wikihow.com/Set-Java-Home)
sourceCompatibility = 1.11

repositories {
    mavenCentral()
}

jlink {
    launcher {
        name = 'exe_name'
    }
}
mainClassName = 'javafx.jlink.example.main/gui.Main'
模块信息.java必须

module javafx.jlink.example.main {
    requires javafx.controls;
    exports gui;
}
Main.java

package gui;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        Button btn = new Button();
        btn.setText("Useless button");

        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
}

这表明您的%PATH_TO_FX%变量不正确。谢谢您的评论。我已验证且变量正确。您可能应该发布变量指向的文件夹的内容。该文件夹包含三个子文件夹/bin/(在Windows上,这将包含一些.dll文件)/legal/(包含许可证)/lib/(这包含一些.jar文件)变量指向lib子文件夹
package gui;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        Button btn = new Button();
        btn.setText("Useless button");

        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
}