简体   繁体   English

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

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

I have a problem, I am currently working on a javafx14 project on eclipse, And the project is almost done.我有一个问题,我目前正在 eclipse 上做一个 javafx14 项目,项目快完成了。

So I exported the application as a runnable jar. But when I try to run it using console by typing.所以我将应用程序导出为可运行的 jar。但是当我尝试通过键入使用控制台运行它时。

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

or或者

java -jar app.jar

or anything really.或任何真的。 It gives me the following它给了我以下

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

or this:或这个:

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

Please Help.请帮忙。 And thanks in advance提前致谢

You must specify the full path to javafx controls.您必须指定 javafx 控件的完整路径。 I recommend using gradle or maven as a picker.我推荐使用 gradle 或 maven 作为选择器。 Using gradle, you can create a bat file that will run your app and take care of the rest.使用 gradle,您可以创建一个 bat 文件,该文件将运行您的应用程序并处理 rest。

project structure项目结构

build.gradle 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 necessarily! modul-info.java一定!

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

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

I resolved the problem by making sure to put the jar file in the same place as the library folder.我通过确保将 jar 文件放在与库文件夹相同的位置来解决问题。

like this:像这样:

-Jar file.

-Folder: lib

So in summary just make sure the jar file is in the same place as your lib.因此,总而言之,只需确保 jar 文件与您的库位于同一位置。

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

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