我正在用JavaFX和OpenJDK 11制作一个简单的电报机器人,我自己的自定义库。这个项目是作为IntelliJ IDEA的JavaFX项目构建的,而Gradle则是构建系统。该库由一个单独的类(Telegram)组成,其中包含一个用于发送消息的函数,并使用JTeleBot库(https://github.com/shibme/jtelebot)。我没有安装JavaFX,而是使用IntelliJ默认JavaFX库,到目前为止,该库在以前的项目中一直运行良好。程序在包含自定义库之前正确打开,但一旦包含它,它就会出现以下错误:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module Telegram not found, required by my.group.project_telegram
有人知道如何解决这个问题吗?require Telegram
包含在module-info.java
文件中。我也试着从头开始重新设计这个项目,但没有结果。以下是我的一些项目文件:
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'
}
模块-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;
}
图书馆:
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
}
}
发布于 2022-04-16 12:58:08
经过一些尝试和错误之后,我最终想出了一个解决方案。正如@珠宝海所说,问题来自于我的图书馆没有一个模块,而只是一个单独的类。在分级文件和这个答案中对此做了进一步的解释。最后,我将以下代码添加到库的build.grade
中:
tasks.named('jar') {
manifest {
attributes('Automatic-Module-Name': 'my.group.Telegram')
}
}
并将我的module-info.java
修改为:
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;
}
如果您不能修改库的文件,这个解决方案可能会工作,但我还没有亲自尝试过。
https://stackoverflow.com/questions/71890127
复制相似问题