javax.json module not found building JavaFX application with Gradle

412 Views Asked by At

I am trying to run a modular JavaFX application, with few other modular and non modular dependencies, using Gradle, but I am stuck with dependencies resolution. The project is in Eclipse, using OpenJDK 14-. I have been able ot run, build and package the same application as non-modular using the org.beryx.runtime pluging https://badass-runtime-plugin.beryx.org/releases/latest/ , but I would like to go a step forward and make it modular, so now I am using the Badass JLink Plugin https://badass-jlink-plugin.beryx.org

To go step by step, I downloaded and tested this example: https://github.com/beryx-gist/badass-jlink-example-log4j2-javafx which is similar to my project and I succesfully ran it. Anyway, Eclipse marks lots of errors due to unresolved imports, which I would like to understand how to remove, but indeed the project compiles and runs. The next step have been to modify this working example by adding the dependencies I need for my real project, which are mainly javax.json and jOpenDocument. The latter cannot be found as a module.

Here is the modified module-info.java

    module hellofx {
    requires javafx.controls;
    requires org.apache.logging.log4j;
    
    requires javax.json;
    requires org.glassfish;

    exports org.openjfx;
    }

and the build.gradle

plugins {
    id 'application'
    id 'org.javamodularity.moduleplugin' version '1.8.9'
    id 'org.openjfx.javafxplugin' version '0.0.10'
    id "org.beryx.jlink" version "2.24.1"
}

repositories {
    mavenCentral()
}

sourceCompatibility = "11"
targetCompatibility = "11"

dependencies {
    implementation 'org.apache.logging.log4j:log4j-core:2.11.1'
    
    implementation 'javax.json:javax.json-api:1.1.4'
    implementation 'org.glassfish:javax.json:1.1.4'
    implementation 'org.jopendocument:jOpenDocument:1.3'
}

javafx {
    version = 16
    modules = ['javafx.controls']
 }

application {
    mainClass = "org.openjfx.HelloFX"
    mainModule = "hellofx"
 }

The compileJava task fails with the following errors:

C:\Users\xxx\badass-jlink-example-log4j2-javafx-master\src\main\java\module-info.java:5: error: module not found: javax.json
    requires javax.json;
                  ^
C:\Users\xxx\badass-jlink-example-log4j2-javafx-master\src\main\java\module-info.java:6: error: module not found: org.glassfish
    requires org.glassfish;

does anybody have a hint to start solving this issue?

1

There are 1 best solutions below

0
CT95 On

The problem seemed to be related to the module-info.class file included in the older javax.json imported as org.glassfish:javax.json:1.1.4. The library has been relocated to jakarta and the new one org.glassfish:jakarta.json:2.0.1 does not show the original problem anymore. So the solution is to switch to the newer library.