20
votes

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.

2
I tried answering this sometime back, I tried creating a similar app using vaadin and was successfully able to deploy it using Tomcat 9(then customised by me). Not certain from the question, what did you stumble upon while trying out deploying a modular jar?Naman
An existing example of a modular jar is jaxb-api.jar version 2.3.0 (link), which one may want to use in WEB-INF/lib of a web app, since javax.xml.bind is deprecated now in the Java API.chris21k
@nullpointer: Java 9 provides the feature of modular jars. With java --module-path lib you can advise the jvm where to search for modular jars. With --add-modules one.java.mod.a you can then set the packages of the module one.java.mod.a say, e.g., in lib/libx.jar onto the classpath of the jvm. This is only possible if lib/libx.jar explicitely exports the module one.java.mod.a. There may be other modules (with other names) in lib/libx.jar or in other jars in the lib directory which are also exported/accessible from outside, say, e.g., one.java.mod.b.chris21k
I have the same question, Tomcat 9 claims support for Java 9, but nowhere in the documentation is any mention of this. And it is 2018 now...ARX
@chris21k this is meta, but I'm kinda surprised that WEB-INF/lib is still a thing. I have the impression that the single application-server, multiple applications deployment model is dead, and with it, the use of multiple, hierarchical classloaders. The last time I saw a single JVM running more than one web application (let alone that these are independenty deployed) is probably a decade ago. If a single JVM runs a single application, you can just pass modules the normal way, and you don't need a drop-in directory. Point is: I wouldn't be too surprised if this is unsupported.Barend

2 Answers

2
votes

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

-3
votes

Tomcat 9 supports java 9

Also as per the stack over flow post -here, Tomcat 9 compatible with java 9 and given the configuration step also.

enter image description here

Tomcat server compatible versions - link