Getting error when using jlink to create a runtime image with Time4J CalendarPicker

427 Views Asked by At

I am using the Time4J library's Persian calendar picker.

When I run the app with ./gradlew run I see it running. But when I launch the JavaFX runtime image of the app, that I build using the Badass JLink Plugin, I get this error:

Caused by: java.util.ServiceConfigurationError: net.time4j.engine.ChronoExtension: module alif.pooya.merged.module does not declare `uses`
    at java.base/java.util.ServiceLoader.fail(Unknown Source)
    at java.base/java.util.ServiceLoader.checkCaller(Unknown Source)
    at java.base/java.util.ServiceLoader.<init>(Unknown Source)
    at java.base/java.util.ServiceLoader.load(Unknown Source)
    at [email protected]/net.time4j.base.ResourceLoader$StdResourceLoader.services(Unknown Source)
    at [email protected]/net.time4j.PlainDate.registerExtensions(Unknown Source)
    at [email protected]/net.time4j.PlainDate.<clinit>(Unknown Source)
    at [email protected]/net.time4j.tz.repo.TimezoneRepositoryProviderSPI.<init>(Unknown Source)
    at [email protected]/net.time4j.tz.repo.TZDATA.init(Unknown Source)
    at [email protected]/main.MainApp.start(Unknown Source)

As you can see from this screenshot, the actual app itself works with /.gradlew run:

Alif Chat, alif desktop chat system © 2020

But when attempting to launch the jlink-generated runtime image with {%project.dir%}/build/image/bin/AlifDesktop, I get the error.

This is how I create the Persian calendar picker:

TZDATA.init(); 
CalendarPicker<PersianCalendar> picker = CalendarPicker.persianWithSystemDefaults();

picker.setLengthOfAnimations(Duration.seconds(0.3));
picker.setShowInfoLabel(true);
picker.setLocale(new Locale("fa", "IR"));
picker.setShowWeeks(true);

picker.setCellCustomizer(
        (cell, column, row, model, date) -> {
            if (CellCustomizer.isWeekend(column, model)) {
                cell.setStyle("-fx-background-color: #FFE0E0;");
                cell.setDisable(false);
            }
        }
);   

And also I used this for build.gradle:

plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.9'
    id 'org.beryx.jlink' version '2.21.4'
}

group 'alif.pooya'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    jcenter()
}

javafx {
    version = "15"
    modules = ['javafx.base', 'javafx.graphics', 'javafx.controls', 'javafx.web','javafx.fxml']
}

dependencies {
    compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.7.2'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
    compile group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.5.1'
    compile group: 'com.jfoenix', name: 'jfoenix', version: '9.0.8'
    compile group: 'net.time4j', name: 'time4j-ui', version: '5.7'
    compile group: 'net.time4j', name: 'time4j-tzdata', version: '5.0-2020a'

}

mainClassName = "$moduleName/main.MainApp"

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    
    launcher {
        name = 'AlifChatDesktop'
        jvmArgs = [
                '-Dnet.time4j.base.useClassloaderOnly=true'
        ]

    }
    
    addExtraDependencies("javafx")
    
}

And this is my module-info.java:

module alif_chat_desktop {

    requires javafx.controls;
    requires javafx.fxml;
    requires okhttp3;
    requires okio.jvm;
    requires kotlin.stdlib.common;
    requires annotations;
    requires Java.WebSocket;
    requires com.jfoenix;
    requires com.google.gson;
    requires slf4j.api;

    requires net.time4j.base;
    requires net.time4j.ui;
    requires net.time4j.tzdb;

    opens main to javafx.fxml;

    exports main;
}
0

There are 0 best solutions below