How to make it possible to use and old jar or automatic module with jlink.
Related error messages:
Error: module-info.class not found for module Error: module not found, required by Error: automatic module cannot be used with jlink: from
Problem and solution
The dependency is not ready to be integrated in a project that uses the module system. It does not have a module-info.
This can be solved in three steps:
generating the module-info.java with jdeps compiling module-info.java into module-info.class with javac injecting the module-info.class in to the jar file Solution on the commandline Make sure that the directory that contains the jar file is actually in jlink's --module-path parameter.
The commands we need to turn the non-modular dependency in to a module look like the following:
jdeps --ignore-missing-deps --module-path <jar_dir_path> --add-modules <module_name --generate-module-info <out_dir_path> <jar_path> javac --patch-module <module_name>=<jar_path> <module-info.java> jar uf <jar_path> -C <module_name> <module-info.class>
Below we have the commands using jsoup as an example. "libs" is the directory containing the jar file, relative to the working directory.
jdeps --ignore-missing-deps --module-path libs --add-modules org.jsoup --generate-module-info libs/tmpOut libs/jsoup-1.15.4.jar javac --patch-module org.jsoup=libs/jsoup-1.15.4.jar libs/tmpOut/module-info.java jar uf libs/jsoup-1.15.4.jar -C libs/tmpOut/org.jsoup module-info.class
Note that jlink will not be able to see the newly created module if we don't have it in the --module path parameter.