The WEB-Inf/lib directory of a web application is for jar files, which a servlet-container (e.g. Tomcat) takes automatically into the classpath of the application. Are there any ideas how this mechanism works (or should work in the future) for modularized jars of Java 9? These provide modules, where the user must specify which contained/exported modules/package should be used by the application. There is a module path additionally to the (old) classpath.
Does a modularized jar work without any further specifications/configurations such that all exported or contained modules are on the classpath then?
Java EE 8 and Tomcat 9 are released. Both projects claim to support Java 9. Thus, there should be a way to use Java 9 modules in a manner that complies to the modules idea.
A Java module is a packaging mechanism that enables you to package a Java application or Java API as a separate Java module. A Java module is packaged as a modular JAR file. A Java module can specify which of the Java packages it contains that should be visible to other Java modules which uses this module.
To set up a module, we need to put a special file at the root of our packages named module-info. java. This file is known as the module descriptor and contains all of the data needed to build and use our new module. We start the module declaration with the module keyword, and we follow that with the name of the module.
A module descriptor is the compiled version of a module declaration that's defined in a file named module-info. java . Each module declaration begins with the keyword module , followed by a unique module name and a module body enclosed in braces, as in: A key motivation of the module system is strong encapsulation.
The module declaration ( module-info. java ) needs to go into your source root directory (e.g. src/main/java ). It then has to be among the list of files to compile, so it will get turned into a module descriptor ( module-info. class ).
While Tomcat doesn't support running modular wars, you can take a look at Piranha Cloud.
The Piranha Server itself can run in the module path and can deploy WARs in a new JPMS layer, respecting the module-info.class provided.
https://piranha.cloud/blog/2021/20210128_Modular_applications_with_JPMS
Disclaimer: I'm a Piranha Cloud developer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With