0

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 alif.pooya.merged.module@1.0-SNAPSHOT/net.time4j.base.ResourceLoader$StdResourceLoader.services(Unknown Source)
    at alif.pooya.merged.module@1.0-SNAPSHOT/net.time4j.PlainDate.registerExtensions(Unknown Source)
    at alif.pooya.merged.module@1.0-SNAPSHOT/net.time4j.PlainDate.<clinit>(Unknown Source)
    at alif.pooya.merged.module@1.0-SNAPSHOT/net.time4j.tz.repo.TimezoneRepositoryProviderSPI.<init>(Unknown Source)
    at alif.pooya.merged.module@1.0-SNAPSHOT/net.time4j.tz.repo.TZDATA.init(Unknown Source)
    at alif_chat_desktop@1.0-SNAPSHOT/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;
}
deduper
  • 1,944
  • 9
  • 22
pooya
  • 1
  • 3
  • The error message sounds as if a line like following is missing in your module-info: `uses net.time4j.engine.ChronoExtension;`. Maybe more service interfaces of Time4J related to resource loading need to be referred too by extra uses-directives. Just try. – Meno Hochschild Sep 19 '20 at 18:52
  • i still get **same error** even adding uses net.time4j.engine.ChronoExtension; in my module-info.java – pooya Sep 20 '20 at 03:25
  • @MenoHochschild do you have any example in github for jlink and javafx to get runtime images? – pooya Sep 20 '20 at 03:27
  • my question is even if it needs declaring uses in module-info , it should need it when running task in gradle, but for running it works ok with no error, when i use jlink to create runtime image i got the error after running the image – pooya Sep 20 '20 at 03:32
  • 1
    „*…do you have any example in github?…*“ — I would like to request the same thing from you, @pooya. If there were a [*minimal reproducible example*](https://stackoverflow.com/help/minimal-reproducible-example) to download and examine, you'd be much more likely to get a solution to your issue; and sooner. TIA. – deduper Sep 21 '20 at 21:42
  • „*I would like to request the same thing from you, @pooya*“ — Never mind. I went ahead and created a [*minimal reproducible example*](https://stackoverflow.com/help/minimal-reproducible-example) of my own. It just prints „*Hello World*“ to the terminal. But even with that, as simple as the app itself is, I was able to reproduce the same issue you reported. I have now resolved it though. Thanks just the same. – deduper Sep 23 '20 at 01:33
  • @deduper did you use this calender and create runtime image , how you fixed it ? how can i see your project codes/ – pooya Sep 23 '20 at 11:04
  • „*…did you use this calender and create runtime image?…*“ – @pooya — Yes and yes. I choose challenging SO Qs as *coding katas*. Yours was good exercise to keep my JPMS/ `jlink` /JavaFX skills sharp and nimble. I also learned more about The Badass JLink Plugin, which has been on my TODO list for more than a year. And of course the Time4J library was a good TIL. So I'm grateful to you for posting the question. Thanks. Speaking of questions: (***1***) *Why didn't you answer mine above?* (***2***) [*Your thoughts on my suggested edits?*](https://stackoverflow.com/suggested-edits/4959031) TIA. – deduper Sep 23 '20 at 13:44
  • @deduper share the answer with the rest of us. – user188757 Feb 23 '22 at 14:37

0 Answers0