1

I am working with JavaFX for the first time and can't run my application. I am using Gradle and added the JavaFx Plugin, everything seemed to work, until I tried to run my application and realised that I need a Runtime Image. The Error: "JavaFX runtime components needed to run this application are missing" showed up. I visited https://openjfx.io/openjfx-docs/ and added the JLink Plugin to my build.gradle file. But now I am getting another error, when I am trying to execute jlink.

Error:

Execution failed for task ':prepareModulesDir'.
> Error while evaluating property 'moduleName' of task ':prepareModulesDir'
   > Failed to query the value of extension 'jlink' property 'moduleName'.
      > Cannot find module-info.java in [C:\Users\nicol\spz_app\dev\App\Spz\spz_app\src\main\java]

build.gradle:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.8.21'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.13'
    id 'org.beryx.jlink' version '2.25.0'
}

group = 'org.spz'
version = '1.0-SNAPSHOT'


repositories {
    mavenCentral()
}



dependencies {
    implementation("com.oracle.database.jdbc:ojdbc11:21.1.0.0")
    implementation("mysql:mysql-connector-java:8.0.28")
    // https://mvnrepository.com/artifact/org.yaml/snakeyaml
    implementation 'org.yaml:snakeyaml:2.0'

}


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

    jlink {
    launcher {
        name = 'Main'
    }
    mergedModule {
        requires "java.xml"
    }

}


Apparently I am missing module-info.java but I am not quite sure, what that is?

Sc4rocko
  • 11
  • 1
  • 1
    See also [*Understanding Java 9 Modules*](https://www.oracle.com/corporate/features/understanding-java-9-modules.html). – trashgod Jul 21 '23 at 16:26
  • 1
    [`jlink`](https://docs.oracle.com/en/java/javase/17/docs/specs/man/jlink.html) only works with modules, it will "assemble and optimize a set of modules and their dependencies into a custom runtime image". If you don't provide module-info for your application (summarized in trashgod's link), then your application is not a module that can be linked. – jewelsea Jul 21 '23 at 20:17
  • For the linker to work, not only your application but *all* of its transitive dependent modules need to be modules with module-info in them (not automatic modules which have no module-info). I am not sure that will be the case with your dependencies. Even if you add module-info for your application, you may still have difficulties linking the application if a dependent module does not provide module-info. – jewelsea Jul 21 '23 at 20:22
  • At least one of your dependencies (`mysql-connector-java`; and maybe Kotlin?) is not modular, so you won't be able to "purely" use `jlink` because, as noted, that tool only works with _explicit modules_. If your goal is to create a self-contained application, then perhaps `jpackage` is appropriate. It uses `jlink` behind the scenes, but can still work with non-modular applications ([including the scenario where your code is modular but depends on non-modular service providers](https://stackoverflow.com/q/76547362/6395627)). – Slaw Jul 21 '23 at 22:13
  • 1
    Additionally, if your application is non-modular, consider the [`org.beryx.runtime`](https://badass-runtime-plugin.beryx.org/releases/latest/) plugin (instead of the `org.beryx.jlink` plugin). – Slaw Jul 21 '23 at 22:15

0 Answers0