1

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?

CT95
  • 107
  • 1
  • 11
  • Check your libraries and see if they are modular (see [this similar issue with building modular gradle apps](https://stackoverflow.com/questions/73984359/unable-to-launch-a-javafx-application-which-uses-apache-poi/73991163#73991163)). I didn't check your libraries to see if they are modules or not. `org.glassfish` is definitely not a module or a library, it is a [maven group id](https://www.baeldung.com/maven-artifact), nor should you be exporting `org.openjfx`. Perhaps study a tutorial on Java modules to understand what they are and how to use them. – jewelsea Oct 10 '22 at 14:13
  • Perhaps in the meantime, you would be better off with a non-modular app (see the documentation at [openjfx.io](https://openjfx.io/openjfx-docs/)), by deleting your `module-info.java`, and ensuring javafx modules are added to your build and execution paths. – jewelsea Oct 10 '22 at 14:17
  • Thanks for your answers. The non modular app is indeed an option and is how it is now; I wished to move to a more modern approach and make it modular. Anyway, the jar files for javax.json (implementation and api) do have a module-info.class inside. I tryed to decompile it with jd but it seems to be corrupted. Maybe this is the reason why it is not working. Right, org.glassfish was a mistake. The export.openjfx was already there, I just modified a sample project. – CT95 Oct 10 '22 at 14:49
  • Oh I see, you are using a sample project with main class `org.openjfx.HelloFX`. At some time in the future you can replace org.openjfx with your own package name and export that, same with HelloFX. But I guess you already know that, I was just confused by your example. – jewelsea Oct 10 '22 at 15:06
  • I think javax.json is outdated, the javax namespace has been replaced with jakarta and new jee artifacts go there (as far as I recall, though I can't find the exact link to that). So an up-to-date version of your lib might be [`implementation group: 'org.glassfish', name: 'jakarta.json', version: '2.0.1'`](https://mvnrepository.com/artifact/org.glassfish/jakarta.json/2.0.1), you can check the [project info page](https://github.com/eclipse-ee4j/jsonp). There are numerous json libs for Java if you have difficulty with that one. – jewelsea Oct 10 '22 at 15:10
  • Actually, it looks like they changed the group name too, in more recent versions (so confusing), so latest is likely [`implementation group: 'jakarta.json', name: 'jakarta.json-api', version: '2.1.1'`](https://mvnrepository.com/artifact/jakarta.json/jakarta.json-api/2.1.1). Module name is [`jakarta.json`](https://github.com/eclipse-ee4j/jsonp/blob/master/api/src/main/java/module-info.java). – jewelsea Oct 10 '22 at 15:26
  • 1
    You right. I took a sample project and started to modify that, instead of flooding you guys with a massive project. Surfing on Maven Central I also found what you say: the implementation of javax.json have been moved to jakarta. I tested the new jar and it appears to work. I successfully decompiled and opened the module-info.class which has valid content now so I guess the corrupted module-info was the problem for the old implementation – CT95 Oct 10 '22 at 16:05
  • You may [answer your own question if you wish](https://stackoverflow.com/help/self-answer), – jewelsea Oct 10 '22 at 19:37

1 Answers1

0

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.

CT95
  • 107
  • 1
  • 11