【问题标题】:I exported a runnable jar using eclipse of my javafx14 application but cannot run the application我使用 javafx14 应用程序的 eclipse 导出了一个可运行的 jar,但无法运行该应用程序
【发布时间】:2020-08-12 17:38:16
【问题描述】:

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

请帮忙。并提前感谢

【问题讨论】:

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

标签: java eclipse javafx fxml executable-jar


【解决方案1】:

您必须指定 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();
    }
}

【讨论】:

    【解决方案2】:

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

    像这样:

    -Jar file.
    
    -Folder: lib
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-25
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多