Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetty 12.0.x documentation #9096

Merged
merged 17 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
[[og-begin-deploy]]
==== Deploying Web Applications

For the purpose of deploying web applications to Jetty, there are two types of resources that can be deployed:
You can deploy two types of web application resources with Jetty:

* Standard Web Application Archives, in the form of `+*.war+` files or web application directories, defined by the Servlet specification.
* *Standard Web Application Archives*, in the form of `+*.war+` files or web application directories, defined by the link:https://www.oracle.com/java/technologies/java-servlet-tec.html[Servlet specification].
Their deployment is described in xref:og-begin-deploy-war[this section].
* Jetty context XML files, that allow you to customize the deployment of standard web applications, and also allow you use Jetty components, and possibly custom components written by you, to assemble your web applications.
* *Jetty context XML files*, that allow you to customize the deployment of standard web applications, and also allow you use Jetty components -- and possibly custom components written by you -- to assemble your web applications.
Their deployment is described in xref:og-deploy[this section].

[[og-begin-deploy-war]]
Expand All @@ -41,12 +41,12 @@ mywebapp.war
----
<1> Publicly accessible resources such as `+*.html+`, `+*.jsp+`, `+*.css+`, `+*.js+` files, etc. are placed in `+*.war+` or in sub-directories of the `+*.war+`.
<2> `WEB-INF` is a special directory used to store anything related to the web application that must not be publicly accessible, but may be accessed by other resources.
<3> `WEB-INF/classes` stores the web application compiled `+*.class+` files
<4> `WEB-INF/classes` stores the web application `+*.jar+` files
<5> `WEB-INF/web.xml` is the web application deployment descriptor defines the components and the configuration of your web application.
<3> `WEB-INF/classes` stores the web application's compiled `+*.class+` files
<4> `WEB-INF/classes` stores the web application's `+*.jar+` files
<5> `WEB-INF/web.xml` is the web application deployment descriptor, which defines the components and the configuration of your web application.
====

To deploy a standard web application, you need to enable the `deploy` module (see the `deploy` module complete definition xref:og-module-deploy[here]).
To deploy a standard web application, we'll need to enable the xref:og-module-deploy[`deploy` module]:
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

----
$ java -jar $JETTY_HOME/start.jar --add-module=deploy
Expand All @@ -57,33 +57,34 @@ $ java -jar $JETTY_HOME/start.jar --add-module=deploy
include::jetty[setupArgs="--add-module=http",args="--add-module=deploy"]
----

The `deploy` module creates the `$JETTY_BASE/webapps` directory, the directory where `+*.war+` files or web application directories should be copied so that Jetty can deploy them.
Activating the `deploy` module will create the `$JETTY_BASE/webapps` directory, which is where Jetty will look for any `+*.war+` files or web application directories to deploy.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

[NOTE]
====
The `deploy` module only provides the feature of deploying web applications.
Activating Jetty's `deploy` module only enables web application deployment. Whether these web applications are served via clear-text HTTP/1.1, or secure HTTP/1.1, or secure HTTP/2, or HTTP/3 (or even all of these protocols) depends on whether the correspondent Jetty modules have been enabled.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

Whether these web applications are served via clear-text HTTP/1.1, or secure HTTP/1.1, or secure HTTP/2, or HTTP/3 (or even all of these protocols) depends on whether the correspondent Jetty modules have been enabled.
Refer to the xref:og-protocols[section about protocols] for further information.
====

Now you need to copy a web application to the `$JETTY_BASE/webapps` directory, and you can use one of the demos shipped with Jetty:
Now let's copy a web application to the `$JETTY_BASE/webapps` directory. We can use one of the demos shipped with Jetty:
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

----
$ java -jar $JETTY_HOME/start.jar --add-module=demo-simple
$ java -jar $JETTY_HOME/start.jar --add-module=ee10-demo-simple
----

The `$JETTY_BASE` directory is now:

----
$JETTY_BASE
$ tree $JETTY_BASE
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
/path/to/jetty.base
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
├── resources
│ └── jetty-logging.properties
├── start.d
│ ├── deploy.ini
│ ├── ee10-demo-simple.ini
│ └── http.ini
└── webapps
└── demo-simple.war
└── ee10-demo-simple.war
----

Now start Jetty:
Expand All @@ -94,14 +95,14 @@ $ java -jar $JETTY_HOME/start.jar

[source,subs=quotes,options=nowrap]
----
include::jetty[setupArgs="--add-modules=http,deploy,demo-simple",highlight="WebAppContext"]
include::jetty[setupArgs="--add-modules=http,deploy,ee10-demo-simple",highlight="WebAppContext"]
----

Note the highlighted line that logs the deployment of `demo-simple.war`.
Note the highlighted line that logs the deployment of `ee10-demo-simple.war`.

Now you can access the web application by pointing your browser to `+http://localhost:8080/demo-simple+`.
Now you can access the web application by pointing your browser to `+http://localhost:8080/ee10-demo-simple+`.

[[og-begin-deploy-war-advanced]]
===== Advanced Deployment

If you want to customize the deployment of your web application, for example by specifying a `contextPath` different from the file/directory name, or by specifying JNDI entries, or by specifying virtual hosts, etc. read xref:og-deploy[this section].
If you want to customize the deployment of your web application -- for example, by specifying a `contextPath` different from the file/directory name, or by specifying JNDI entries, or by specifying virtual hosts -- read xref:og-deploy[this section].
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
[[og-begin-install]]
==== Installing Jetty

After the download, unpacking Eclipse Jetty will extract the files into a directory called `jetty-home-VERSION`, where `VERSION` is the version that you downloaded, for example `{version}`, so that the directory is called `jetty-home-{version}`.

Unpack Eclipse Jetty compressed file in a convenient location, for example under `/opt`.

CAUTION: For Windows users, you should unpack Jetty to a path that does not contain spaces.

The rest of the instructions in this documentation will refer to this location as `$JETTY_HOME`, or `${jetty.home}`.
After the download, unpacking Eclipse Jetty will extract the files into a directory called `jetty-home-VERSION`, where `VERSION` is the version of Jetty that you downloaded. For example, installing Jetty {version} will create a directory called `jetty-home-{version}`.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

IMPORTANT: It is important that *only* stable release versions are used in production environments.
Versions that have been deprecated or are released as Milestones (M), Alpha, Beta or Release Candidates (RC) are *not* suitable for production as they may contain security flaws or incomplete/non-functioning feature sets.

Unpack Eclipse Jetty file into a convenient location, such as `/opt`. The rest of the instructions in this documentation will refer to this location as `$JETTY_HOME`, or `${jetty.home}`.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

CAUTION: For Windows users, you should unpack Jetty to a path that does not contain spaces.

If you are new to Jetty, you should read the xref:og-arch[Jetty architecture section] to become familiar with the terms used in this documentation.
Otherwise, you can jump to the xref:og-begin-start[section on starting Jetty].
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
[[og-begin-start]]
==== Starting Jetty

Eclipse Jetty as a standalone server has no graphical user interface, so configuring and running the server is done from the command line.
Eclipse Jetty as a standalone server has no graphical user interface; configuring and running the server is done from the command line.

Recall from the xref:og-arch[architecture section] that Jetty is based on xref:og-modules[modules], that provides features, and on xref:og-arch-jetty-base[`$JETTY_BASE`], the place where you configure which module (and therefore which feature) you want to enable, and where you configure module parameters.

Jetty is started by executing `$JETTY_HOME/start.jar` from within a `$JETTY_BASE` directory, so first we need to create a `$JETTY_BASE`:
First we need to create a `$JETTY_BASE` directory.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

----
$ JETTY_BASE=/path/to/jetty.base
$ mkdir $JETTY_BASE
$ cd $JETTY_BASE
----

If you try to start Jetty from an empty `$JETTY_BASE` you get:
We'll start Jetty by executing `$JETTY_HOME/start.jar` from this directory. However, if we try to start Jetty from an empty `$JETTY_BASE`, it will complain that we haven't enabled any modules:
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

----
$ java -jar $JETTY_HOME/start.jar
Expand All @@ -36,28 +35,32 @@ $ java -jar $JETTY_HOME/start.jar
include::jetty[]
----

Jetty exited complaining that there are no modules enabled, since the `$JETTY_BASE` you just created is empty and therefore there is no configuration to read to assemble the Jetty server.
Jetty uses a xref:og-modules[module] system to configure and assemble its web server; these modules are enabled and configured in xref:og-arch-jetty-base[`$JETTY_BASE`]. Since the `$JETTY_BASE` directory we just created is empty, Jetty has no configuration it can use to assemble the server.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

However, it shows that `start.jar` takes parameters, whose details can be found in xref:og-start[this section].
NOTE: See the xref:og-arch[architecture section] of this document for more information on the design of Jetty's module system.

You can explore what modules are available out of the box via:
You can explore what modules are available with the `--list-modules` flag:

----
$ java -jar $JETTY_HOME/start.jar --list-modules=*
----

Let's try to enable the `http` module (see also xref:og-protocols-http[this section] for additional information):
Let's try to enable the xref:og-protocols-http[`http`] module.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

NOTE: If you want to enable support for protocols like secure HTTP/1.1 or HTTP/2 or HTTP/3, or want to configure Jetty behind a load balancer, read xref:og-protocols[this section].

----
$ java -jar $JETTY_HOME/start.jar --add-module=http
----

[source,options=nowrap]
[source,subs=quotes,options=nowrap]
----
include::jetty[args="--add-module=http"]
include::jetty[args="--add-module=http",highlight="([a-z\-]+ *transitively enabled)"]
----

Now you can start Jetty:
Note that Jetty has enabled a number of transitive dependencies (`server`, `logging-jetty`, and so on) in order to activate the `http` module.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

Now we can start Jetty:
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

----
$ java -jar $JETTY_HOME/start.jar
Expand All @@ -68,24 +71,27 @@ $ java -jar $JETTY_HOME/start.jar
include::jetty[args="--module=http",highlight="(\{.*:8080})"]
----

Note how Jetty is listening on port `8080` for clear-text HTTP/1.1 connections.
Jetty is listening on port `8080` for clear-text HTTP/1.1 connections. However, since it has no web applications deployed, it will just reply with `404 Not Found` to every request.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

After having enabled the `http` module, the `$JETTY_BASE` directory looks like this:
Before we xref:og-begin-deploy[deploy our first web application], let's see what's happened to the `$JETTY_BASE` directory now that we've enabled the `http` module:
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

[source,subs=verbatim]
----
JETTY_BASE
$ tree $JETTY_BASE
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
/path/to/jetty.base
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
├── resources
│ └── jetty-logging.properties <1>
└── start.d <2>
└── http.ini <3>
----

<1> The `resources/jetty-logging.properties` file has been created because the `http` modules depends on the `server` module, which in turn depends on the `logging` module; the `logging` module created this file that can be configured to control the server logging level.
<2> The `start.d/` directory contains the configuration files for the modules.
<3> The `start.d/http.ini` file is the `http` module configuration file, where you can specify values for the `http` module properties.
<1> The `resources/jetty-logging.properties` file configures the server's logging level. This file was auto-generated when the `jetty-logging` module was activated as a transitive dependency of the `http` module.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
<2> The `start.d/` directory contains configuration files for any modules you have explicitly activated.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
<3> The `start.d/http.ini` file is the `http` module configuration file, where you can specify values for the xref:og-module-http[`http` module properties].

NOTE: By default, Jetty does not generate configuration files in `start.d/` for modules activated as transitive dependencies. To manually configure such a module, you should activate it directly via Jetty's `--add_module` flag.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

In the `http.ini` file you can find the following content (among other content):
In the `http.ini` file we can find the following (among other contents):
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

.http.ini
[source,subs=verbatim]
Expand All @@ -96,15 +102,9 @@ In the `http.ini` file you can find the following content (among other content):
----

<1> This line enables the `http` module and should not be modified.
<2> This line is commented out and specifies the default value for the module property `jetty.http.port`, which is the network port that listens for clear-text HTTP connections.
<2> This commented line specifies the default value for the `jetty.http.port` property, which is the network port that Jetty uses to listen for clear-text HTTP connections.

You can change the module property `jetty.http.port` value directly from the command line:

----
$ java -jar $JETTY_HOME/start.jar jetty.http.port=9999
----

To make this change persistent, you can edit the `http.ini` file, uncomment the module property `jetty.http.port` and change its value to `9999`:
Let's change that default port. Open `http.ini`, uncomment the line containing `jetty.http.port=`, and change its value to `9999`:
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

.http.ini
----
Expand All @@ -113,7 +113,7 @@ jetty.http.port=9999
...
----

If you restart Jetty, the new value will be used:
If you restart Jetty, it will use this new value:

----
$ java -jar $JETTY_HOME/start.jar
Expand All @@ -124,11 +124,15 @@ $ java -jar $JETTY_HOME/start.jar
include::jetty[args="--module=http jetty.http.port=9999",highlight="(\{.*:9999})"]
----

Note how Jetty is now listening on port `9999` for clear-text HTTP/1.1 connections.
You can also specify the value of a module property when you start up Jetty. A property value specified on the command-line in this way will *override* the value configured in a module's `.ini` file.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

NOTE: If you want to enable support for different protocols such as secure HTTP/1.1 or HTTP/2 or HTTP/3, or configure Jetty behind a load balancer, read xref:og-protocols[this section].
----
$ java -jar $JETTY_HOME/start.jar jetty.http.port=8080
----

The Jetty server is now up and running, but it has no web applications deployed, so it just replies with `404 Not Found` to every request.
It is time to xref:og-begin-deploy[deploy your web applications] to Jetty.
[source,subs=quotes,options=nowrap]
----
include::jetty[args="--module=http jetty.http.port=8080",highlight="(\{.*:8080})"]
----

For more detailed information about the Jetty start mechanism, you can read the xref:og-arch-start[Jetty start mechanism] section.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ own custom link:https://docs.oracle.com/javase/7/docs/api/javax/security/auth/sp
[[og-jaas-module]]
===== The `jaas` module

Enable the `jaas` module:
Enable the `ee{8,9,10}-jaas` module appropriate for your EE platform:

----
include::{JETTY_HOME}/modules/jaas.mod[]
include::{JETTY_HOME}/modules/ee10-jaas.mod[]
----

The configurable items in the resulting `$jetty.base/start.d/jaas.ini` file are:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,31 @@ Only modules conforming to the "Servlet Container Profile" with the ServerAuthMo
Enable the `jaspi` module:

----
include::{JETTY_HOME}/modules/jaspi.mod[]
include::{JETTY_HOME}/modules/ee9-jaspi.mod[]
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
----

[[og-jaspi-xml]]
===== Configure JASPI

To enable the `jaspi` module you can use the following command (issued from within the `$JETTY_BASE` directory):
Activate the `ee{9,10}-jaspi` module that matches your EE platform version.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a module exists for ee9, then it should also exist for ee8, since we mechanically generate ee8 from ee9.
I'd say to always use ee{8,9,10} everywhere so here ee{9,10} -> ee{8,9,10}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd – when I run java -jar $JETTY_HOME/start.jar --list-modules=* | grep jaspi I get:

                            ee10-jaspi - Enables JASPI authentication for deployed web applications.
ee10-jaspi-default-auth-config-factory - Provides a DefaultAuthConfigFactory for jaspi
                       ee10-jaspi-demo - Enables JASPI basic authentication the /test context path.
                             ee9-jaspi - Enables JASPI authentication for deployed web applications.
 ee9-jaspi-default-auth-config-factory - Provides a DefaultAuthConfigFactory for jaspi
                        ee9-jaspi-demo - Enables JASPI basic authentication the /test context path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olamy do you know whether there is a ee8-jaspi module?


----
$ java -jar $JETTY_HOME/start.jar --add-modules=jaspi
$ java -jar $JETTY_HOME/start.jar --add-modules=ee9-jaspi
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
----

You can then register a `AuthConfigProvider` onto the static `AuthConfigFactory` obtained with `AuthConfigFactory.getFactory()`. This registration can be done in the XML configuration file which will be copied to `$JETTY_BASE/etc/jaspi/jaspi-authmoduleconfig.xml` when the module is enabled.

====== JASPI Demo
The `jaspi-demo` module illustrates setting up HTTP Basic Authentication using a Jakarta Authentication module that comes packaged with jetty: `org.eclipse.jetty.security.jaspi.modules.BasicAuthenticationAuthModule`, and applies it for a context named `/test`.
The `ee9-jaspi-demo` and `ee10-jaspi-demo` modules illustrate setting up HTTP Basic Authentication using the EE9 and EE10 Jakarta Authentication modules that come packaged with Jetty.

The following example uses Jetty's EE9 implementation of `AuthConfigProvider` to register a `ServerAuthModule` directly.
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved

[source, xml]
----
include::{JETTY_HOME}/etc/jaspi/jaspi-demo.xml[]
include::{JETTY_HOME}/etc/jaspi/jetty-ee9-jaspi-demo.xml[]
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
----

This example uses the `AuthConfigProvider` implementation provided by Jetty to register a `ServerAuthModule` directly. Other custom or 3rd party modules that are compatible with the `ServerAuthModule` interface in JASPI can be registered in the same way.
Other custom or 3rd party modules that are compatible with the `ServerAuthModule` interface in JASPI can be registered in the same way.

===== Integration with Jetty Authentication Mechanisms

Expand All @@ -61,8 +63,8 @@ The `CallerPrincipalCallback` and `GroupPrincipalCallback` do not require use of

Jetty provides an implementation of the `AuthConfigFactory` interface which is used to register `AuthConfigProviders`. This can be replaced by a custom implementation by adding a custom module which provides `auth-config-factory`.
This custom module must reference an XML file which sets a new instance of the `AuthConfigFactory` with the static method `AuthConfigFactory.setFactory()`.
For an example of this see the `jaspi-default-auth-config-factory` module, which provides the default implementation used by Jetty.
For an example of this see the `ee{9,10}-jaspi-default-auth-config-factory` module, which provides the default implementation used by Jetty.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ee{9,10} -> ee{8,9,10}.


----
include::{JETTY_HOME}/modules/jaspi-default-auth-config-factory.mod[]
include::{JETTY_HOME}/modules/ee9-jaspi-default-auth-config-factory.mod[]
gregpoulos marked this conversation as resolved.
Show resolved Hide resolved
----
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
[[og-jsp]]
=== Java Server Pages

Jetty supports JSP via the `jsp` module, which is based on Apache Jasper:
Jetty supports JSP via the `ee{8,9,10}-jsp` modules, which are based on Apache Jasper:

----
include::{JETTY_HOME}/modules/jsp.mod[]
include::{JETTY_HOME}/modules/ee10-jsp.mod[]
----

Logging has been bridged to Jetty logging, so you can enable logging for the `org.apache.jasper` package, subpackages and classes as usual.
Expand Down Expand Up @@ -172,10 +172,10 @@ If the value you set doesn't take effect, try using all lower case instead of ca

=== JavaServer Pages Standard Tag Libraries

The JavaServer Pages Standard Tag Library (JSTL) is part of the Jetty distribution, and is available via the `jstl` module:
The JavaServer Pages Standard Tag Library (JSTL) is part of the Jetty distribution, and is available via the `ee{8,9,10}-jstl` modules:

----
include::{JETTY_HOME}/modules/jstl.mod[]
include::{JETTY_HOME}/modules/ee10-jstl.mod[]
----

When enabled, Jetty will make the JSTL tags available for your webapps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ include::{JETTY_HOME}/modules/requestlog.mod[tags=documentation]

The property `jetty.requestlog.formatString` can be customized using format codes.

include::javadoc[file=jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java,xsl=src/main/asciidoc/operations-guide/modules/module-requestlog.xsl,tags=documentation,replace="\|,\\|"]
include::javadoc[file=jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java,xsl=src/main/asciidoc/operations-guide/modules/module-requestlog.xsl,tags=documentation,replace="\|,\\|"]
Loading