21

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.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
chris21k
  • 241
  • 1
  • 7
  • I tried [answering this](https://stackoverflow.com/questions/45766064/run-vaadin-8-1-app-under-java-9-prerelease-in-intellij-2017-2-2) 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 Oct 07 '17 at 08:49
  • An existing example of a modular jar is `jaxb-api.jar` version 2.3.0 ([link](https://javaee.github.io/jaxb-v2/doc/user-guide/release-documentation.html#running-on-java-9)), 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 Oct 07 '17 at 12:04
  • 2
    @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 Oct 07 '17 at 12:05
  • 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 Jan 11 '18 at 02:48
  • @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 Nov 24 '19 at 13:20
  • Have you read the appropriate servlet specification? – Thorbjørn Ravn Andersen Mar 08 '21 at 22:18

2 Answers2

2

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

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

DAIRAV
  • 723
  • 1
  • 9
  • 31
  • 5
    The original question is how Java 9 modules are supported (if at all) by Webapplications (1. by the JEE standard and 2. by Tomcat).That Java 9 can run Tomcat is clear. – chris21k Apr 05 '18 at 07:43