【问题标题】:CalendarFX in combination with JavaFX: Module javafx.controls not foundCalendarFX 与 JavaFX 结合使用:找不到模块 javafx.controls
【发布时间】:2020-03-21 18:41:21
【问题描述】:

我试图在我的 JavaFX 项目中使用CalendarFX 作为 gradle 依赖项与gradle javafx plugin,但我得到了模块 javafx.controls 未找到的错误,同时在 build.gradle 文件中明确指定它应该使用javafx.controls 模块。我的设置是这样的:

build.gradle:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

group 'org.example'
version '1.0-SNAPSHOT'

mainClassName = "org.example.MainApp"

sourceCompatibility = 13

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.calendarfx:view:11.8.3'
}

javafx {
    version = "13"
    modules = ['javafx.controls', 'javafx.fxml']
}

MainApp.java:

package org.example;

import com.calendarfx.model.Calendar;
import com.calendarfx.model.CalendarSource;
import com.calendarfx.view.CalendarView;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.time.LocalDate;
import java.time.LocalTime;

public class MainApp extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        CalendarView calendarView = new CalendarView();

        Calendar test = new Calendar("Test");
        test.setShortName("T");
        test.setStyle(Calendar.Style.STYLE1);

        CalendarSource familyCalendarSource = new CalendarSource("Source");
        familyCalendarSource.getCalendars().add(test);

        calendarView.getCalendarSources().setAll(familyCalendarSource);
        calendarView.setRequestedTime(LocalTime.now());

        StackPane stackPane = new StackPane();
        stackPane.getChildren().add(calendarView);

        Thread updateTimeThread = new Thread("Calendar: Update Time Thread") {
            @Override
            public void run() {
                while (true) {
                    Platform.runLater(() -> {
                        calendarView.setToday(LocalDate.now());
                        calendarView.setTime(LocalTime.now());
                    });

                    try {
                        // update every 10 seconds
                        sleep(10000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        };

        updateTimeThread.setPriority(Thread.MIN_PRIORITY);
        updateTimeThread.setDaemon(true);
        updateTimeThread.start();

        Scene scene = new Scene(stackPane);
        primaryStage.setTitle("Calendar");
        primaryStage.setScene(scene);
        primaryStage.setWidth(1300);
        primaryStage.setHeight(1000);
        primaryStage.centerOnScreen();
        primaryStage.show();
    }
}

当我尝试运行时遇到的错误是:

$ ./gradlew run

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

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 738ms
3 actionable tasks: 2 executed, 1 up-to-date

【问题讨论】:

  • 你能试试./gradlew clean --info run吗? (您将看到打印了用于运行项目的完整命令行)。
  • 嗨,我刚刚运行命令,结果如下:pastebin.com/c0c6X80q 我发现这个错误真的很奇怪,因为在完整运行命令中它显示 javafx.controls 包,并且在命令之后,它说“找不到模块 javafx.controls”。
  • 这可能与 CalendarFX 依赖于 JavaFX 13.0.1 并且您使用的是 13.0 的事实有关。不知何故,javafx.controls jar 从模块路径移动到了类路径。你能试试version="13.0.2",甚至version="14"吗?
  • 我尝试了两个版本,不幸的是,不幸的是,仍然“错误:JavaFX 运行时组件丢失,并且是运行此应用程序所必需的”
  • 您可以尝试从 CalendarFX 中排除 openJFX 依赖项吗?喜欢dependencies { implementation ('com.calendarfx:view:11.8.3') { exclude group: 'org.openjfx', module: '' }}

标签: java gradle javafx


【解决方案1】:

在你的虚拟机参数中试试这个:

--module-path \path\to\javafx-sdk\lib --add-modules=javafx.controls,javafx.fxml

【讨论】:

    【解决方案2】:

    JavaFx 不附带 CalendarFx , 下载该库并将其导入您的项目中。

    https://github.com/dlsc-software-consulting-gmbh/CalendarFX/releases/download/11.8.3/view-11.8.3.jar

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-16
      • 2019-06-01
      • 1970-01-01
      • 2020-03-13
      • 2019-05-06
      • 1970-01-01
      • 2021-02-10
      • 2019-05-07
      相关资源
      最近更新 更多