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

我有一个问题,我目前正在eclipse上的一个javafx14项目上工作,而该项目快要完成了。

所以我将应用程序导出为可运行的jar。但是,当我尝试通过控制台使用控制台运行它时。

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

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

请帮助。并预先感谢

iCMS 回答:我使用javafx14应用程序的eclipse导出了可运行的jar,但无法运行该应用程序

您必须指定javafx控件的完整路径。我建议使用gradle或maven作为选择器。使用gradle,您可以创建一个bat文件,该文件将运行您的应用程序并负责其余的工作。

project structure

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'
必定要

modul-info.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();
    }
}
本文链接:https://www.f2er.com/1757067.html

大家都在问