0

I am making a simple Telegram bot with my own custom library in JavaFX with OpenJDK 11. The project was built as a JavaFX project from IntelliJ IDEA, with Gradle as build system. The library consists of a single class (Telegram) with a single function to send a message, and uses the JTeleBot library (https://github.com/shibme/jtelebot). I do NOT have JavaFX installed, I am instead using the IntelliJ default JavaFX libraries, which has been working fine until now for previous projects. The program opens properly before including the custom library, but as soon as I include it, it gives the following error:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module Telegram not found, required by my.group.project_telegram

Does anybody have any idea on how to fix this? require Telegram is included in the module-info.java file. I have also tried remaking the project from scratch, with no results. Here are some of my project files:

build.gradle:

    plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.10'
    id 'org.beryx.jlink' version '2.24.1'
}

group 'my.group'
version '1.0'

repositories {
    mavenCentral()
    maven {
        url "https://gitlab.com/api/v4/projects/<project-id>/packages/maven"
        credentials(HttpHeaderCredentials) {
            name = "Private-Token"
            value = gitLabPrivateToken // the variable resides in ~/.gradle/gradle.properties
        }
        authentication {
            header(HttpHeaderAuthentication)
        }
    }
}

ext {
    junitVersion = '5.8.2'
}

sourceCompatibility = '11'
targetCompatibility = '11'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

application {
    mainModule = 'my.group.project_telegram'
    mainClass = 'my.group.project_telegram.HelloApplication'
}

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

dependencies {
    implementation('my.group:Telegram:1.0')
    implementation('org.controlsfx:controlsfx:11.1.1')
    implementation('com.dlsc.formsfx:formsfx-core:11.5.0') {
        exclude(group: 'org.openjfx')
    }

    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}

test {
    useJUnitPlatform()
}

jlink {
    imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip") as RegularFile
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'app'
    }
}

jlinkZip {
    group = 'distribution'
}

module-info.java:

module my.group.project_telegram {
    requires javafx.controls;
    requires javafx.fxml;

    requires org.controlsfx.controls;
    requires com.dlsc.formsfx;
    requires Telegram;

    opens my.group.project_telegram to javafx.fxml;
    exports my.group.project_telegram;
}

The library:

package pkgTelegram;

import me.shib.java.lib.telegram.bot.service.TelegramBot;
import me.shib.java.lib.telegram.bot.types.*;

import java.io.IOException;

public class Telegram {

    public static void sendToTelegram(String apiToken, String chatId, String text) {
        // the function's code
    }
}
Endyxion
  • 45
  • 1
  • 6
  • 1
    You don't have a module named `Telegram`. JavaFX is irrelevant to this. You have a misconfiguration when trying to use the Java Platform Module System. – jewelsea Apr 16 '22 at 07:17

1 Answers1

0

After some trial and error, I ended up coming up with a solution. As @jewelsea said, the problem came from the fact that my library did not have a module, and instead is just a single class. The is explained further in the Gradle documentation and in this answer. I ended up adding the following code to my library's build.grade :

tasks.named('jar') {
    manifest {
        attributes('Automatic-Module-Name': 'my.group.Telegram')
    }
}

and modified my module-info.java to:

module my.group.project_telegram {
    requires javafx.controls;
    requires javafx.fxml;

    requires org.controlsfx.controls;
    requires com.dlsc.formsfx;
    requires my.group.Telegram;

    opens my.group.project_telegram to javafx.fxml;
    exports my.group.project_telegram;

}

If you can't modify your library's files, this solution might work, but I haven't tried it myself.

Endyxion
  • 45
  • 1
  • 6