I got an error every time I try to run the javaFX application generated by Intelij. I selected kotlin langage to code and i use gradle version 8.7. The error say that he can’t find the package in module
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: D:\Dev\InteliJ\Intelij Project\ChatApplication\ChatApplicationDesktop\build\classes\java\main
Caused by: java.lang.module.InvalidModuleDescriptorException: Package fr.plaglefleau.chatapplicationdesktop not found in module
But the package does exist and does have kotlin class in it.
package fr.plaglefleau.chatapplicationdesktop
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Scene
import javafx.stage.Stage
class HelloApplication : Application() {
override fun start(stage: Stage) {
val fxmlLoader = FXMLLoader(HelloApplication::class.java.getResource("hello-view.fxml"))
val scene = Scene(fxmlLoader.load(), 320.0, 240.0)
stage.title = "Hello!"
stage.scene = scene
stage.show()
}
fun main() {
Application.launch(HelloApplication::class.java)
}
}
package fr.plaglefleau.chatapplicationdesktop
import javafx.fxml.FXML
import javafx.scene.control.Label
class HelloController {
@FXML
private lateinit var welcomeText: Label
@FXML
private fun onHelloButtonClick() {
welcomeText.text = "Welcome to JavaFX Application!"
}
}
(don’t know if it’s relevant to post this code here)
I try to regenerate the project in java and still got the same error. I also try to open my module
open module fr.plaglefleau.chatapplicationdesktop {
requires javafx.controls;
requires javafx.fxml;
requires kotlin.stdlib;
exports fr.plaglefleau.chatapplicationdesktop;
}
plugins {
id 'java'
id 'application'
id 'org.jetbrains.kotlin.jvm' version '1.8.22'
id 'org.javamodularity.moduleplugin' version '1.8.12'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
}
group 'fr.plaglefleau'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.10.0'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'fr.plaglefleau.chatapplicationdesktop'
mainClass = 'fr.plaglefleau.chatapplicationdesktop.HelloApplication'
}
kotlin {
jvmToolchain(17)
}
javafx {
version = '21'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
implementation("org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC")
}
test {
useJUnitPlatform()
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
I obviously also try with the generated module-info.java
module fr.plaglefleau.chatapplicationdesktop {
requires javafx.controls;
requires javafx.fxml;
requires kotlin.stdlib;
opens fr.plaglefleau.chatapplicationdesktop to javafx.fxml;
exports fr.plaglefleau.chatapplicationdesktop;
}