How to inject module declaration into JAR?

Yes, this is possible with the --patch-module option. This option is most often used at runtime, but it also works at compile time:

javac --patch-module <module name>=<path to jar> module-info.java

Alternatively, to compile the module-info.java generated you need to also extract the contents of the JAR to a directory.

Then compile the module-info.java with the output directory (-d) set to the directory where you extracted the contents.

Credits :- Alan