javamodulejlinkruntime-environment

jlink module XXX not found


I am using jdk 10, windows 8 and eclipse 2019 which I used to make my jar file. I want to make a custom jre using the jlink tool, I am countering a problem that jlink is not able to detect my jar file that is made from eclipse. However, I have already installed too many java versions, this is my command :

"C:\Program Files\Java\jdk-10.0.2\bin\jlink.exe" --module-path "C:\Users\Hassan\Desktop\test_java.jar";"C:\Program Files\Java\jdk-10.0.2\jmods" --add-modules test_java --output \Test2\JRE --compress=2

and it returns :

Error: Module test_java is not found.

I am sure that the path is correct. I don't know what is happening, I wrote the command correctly along with their paths.


Solution

  • After I searched on the internet, I found out that I did not create a module, I only created a jar file that has no module. In order to add a module into my java application, I have to add a java file called module-info.java, this is a special file that has no classes, it contains the modules that is needed inside my java application. module-info.java must not be under the possession of any package. After using jdeps.exe to determine what modules does my application need to run. So, I wrote this code inside module-info.java :

    module AnyNameWillWork {
      requires java.base;
      requires javafx.base;
      requires javafx.controls;
      requires javafx.graphics;
      exports application;
    }
    

    exports keyword gives the required modules the permission to the followed package to use them. All my app classes are inside application package.

    If my answer has some mistakes, please comment my answer out for any corrections.