Jetty and the Java Module System.
Java 9 introduced the arguably biggest change in the Java platform since its inception, the Java Module System (a.k.a. Project Jigsaw, or Java Platform Module System – JPMS).
The Java Module System primarily targets the modularization of the JDK itself, but can also be used to write modularized applications.
Historically, Jetty has been often used to write applications that needed to embed an HTTP server without having too many dependencies. The fact that Jetty itself is a highly modular set of components allows you to use only the Jetty components that you need, reducing the dependencies and keeping your single application jar small.
For example, you may need to embed Jetty as an HTTP server only, without the need for JSPs, without support for WebSocket, without HTTP/2: Jetty allows you to do that.
You will be able to mix and match Jetty features by simply adding dependencies on the Jetty modules you need.
Since Jetty is already modularized into Jetty modules, it would be great if a JPMS application could reference Jetty modules as JPMS modules.
This is now possible since Jetty 9.4.14.
JPMS modules for Jetty 9.4.x and Jetty 10.0.x
To make Jetty modules available as JPMS modules we have taken a two-steps approach.
First, the Jetty 9.4.x series now include the entryAutomatic-Module-Name
in the fileMANIFEST.MF
of each jar representing a Jetty module.
This allowed us to lock down the definition of the Jetty JPMS module names, in the form of org.eclipse.jetty.*
names.
For example, the jetty-util
Jetty module has a JPMS module name of org.eclipse.jetty.util
, and so forth for other Jetty modules.
Second, the Jetty 10.0.x series will include a proper module-info.java
JPMS module file for each Jetty module. This will allow us to take advantage of the JPMS module system and hiding implementation classes that we don’t want to expose.
With stable Jetty JPMS module names, JPMS applications that use proper module-info.java
JPMS module files can reliably reference JPMS Jetty modules by name, and little will change when they will update their Jetty version from 9.4.x to 10.0.x (where Jetty will also use proper module-info.java
JPMS module files).
Running Jetty standalone on the module-path
But Jetty is also a great standalone server!
It is now possible to run Jetty as a standalone server on the module-path rather than on the class-path as it has always been.
To run Jetty as a standalone server on the module-path, you just need to add an additional command line option, namely --jpms
:
# Create a new JETTY_BASE directory. $ mkdir jetty-base $ cd jetty-base # Configure the HTTP module. $ java -jar $JETTY_HOME/start.jar --add-to-start=http # Start Jetty on the module-path. $ java -jar $JETTY_HOME/start.jar --jpms
That is all!
Note that this will run the Jetty server on the module path.
Web applications deployed to Jetty will not take advantage of the JPMS module system (yet).
Making Web application take advantage of the JPMS module system is a matter for the Eclipse EE4J effort, but we may anticipate that effort in Jetty 10.0.x with some experiments on our own (if you are interested, follow this Jetty enhancement issue).
We recommend using Java 11 to run Jetty on the module-path.
Follow the Jetty JPMS documentation if you want to know more details about how to customize Jetty modules so that they are JPMS friendly, and let us know what you think!
0 Comments