Home > Mobile >  Java required module can't be found
Java required module can't be found

Time:11-03

I have a basic JavaFX project set up in IntelliJ:

enter image description here

The project uses Gradle for dependency management. The dependency that was added by my is javax.mail.api as you can see in the build.gradle file here:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.13'
    id 'org.beryx.jlink' version '2.25.0'
}

group 'com.contoso'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

ext {
    junitVersion = '5.9.0'
}

sourceCompatibility = '18'
targetCompatibility = '18'

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

application {
    mainModule = 'com.contoso.portwatcher'
    mainClass = 'com.contoso.portwatcher.Application'
}

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

dependencies {

    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
    implementation group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'

}

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'
}

The iissue I have now is that when trying to execute to programm with the following run configuration:

enter image description here

I get the following exception:

enter image description here

The module-info.java file specifies the added dependency module:

module com.contoso.portwatcher {
    requires javafx.controls;
    requires javafx.fxml;
    requires javax.mail.api;


    opens com.contoso.portwatcher to javafx.fxml;
    exports com.contoso.portwatcher;
}

My question is why the module cannot be found?

Thank you for your patience and help.

CodePudding user response:

The mail API jar from your dependency doesn't define a module-info.class.

The new Jakarta mail API does define the file. Migrate your usage of javax.mail to jakarta.mail packages and use the updated artifact, should work then.

  • Related