繁体   English   中英

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

[英]I exported a runnable jar using eclipse of my javafx14 application but cannot run the application

我有一个问题,我目前正在 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

请帮忙。 提前致谢

您必须指定 javafx 控件的完整路径。 我推荐使用 gradle 或 maven 作为选择器。 使用 gradle,您可以创建一个 bat 文件,该文件将运行您的应用程序并处理 rest。

项目结构

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

主.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();
    }
}

我通过确保将 jar 文件放在与库文件夹相同的位置来解决问题。

像这样:

-Jar file.

-Folder: lib

因此,总而言之,只需确保 jar 文件与您的库位于同一位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM