Once you start breaking down your library JARs into modules, depending on the size of your library, you may have a lot of work to do. It's not straightforward to identify which modules you'll need to require and which you'll need to export. The jdeps tool has another trick up its sleeve. It can look at your JAR files and automatically come up with module descriptors for you to use.
The syntax is as follows:
$ jdeps --generate-module-info <output-location> <path-to-jars>
Let's try this for the commons-collections JAR file:
$ jdeps --generate-module-info out lib/commons-collections4-4.1.jar
The output should look like this:
writing to out/commons.collections4/module-info.java
As you can see, jdeps has generated a module root folder with the same automatic naming algorithm we've seen before. Inside that folder, it has created a module-info.java file that it has populated with the requires and exports declarations that it identified by scanning the classes in the JARs:
module commons.collections4 {
requires transitive java.xml;
exports org.apache.commons.collections4;
...
}
You can run this command and point to multiple JARs, and it'll do this for every single JAR, which also benefits from any relationships between the JARs. The generated module-info.java files for those related modules will include the relationship too!