Jetty Logo
Version: 9.2.11-SNAPSHOT
Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Chapter 12. Annotations

Table of Contents

Quick Setup
Working with Annotations
Using Annotations with Jetty Embedded

Jetty supports the servlet specification annotations. It is not enabled by default, so the following sections show you how to enable it, and how to use them.

Quick Setup

Jetty Distribution

If you are using the jetty distribution, then annotations are enabled by default. The annotations module and its transitive dependencies are responsible for making annotation processing available.

Note that annotations that relate to JNDI, such as @Resource and @Resources are enabled via the jndi module, which is a transitive dependency on the annotations module, and thus is also enabled by default for the distribution.

Jetty Maven Plugin

Annotations and JNDI are pre-enabled for the maven plugin.

Embedding

To use annotations in an embedded scenario, you will need to include the jetty-annotations jar and all its dependencies onto your classpath, and you will also need to include the org.eclipse.jetty.annotations.AnnotationConfiguration into the list of Configuration classes applied to the org.eclipse.jetty.webapp.WebAppContext representing your webapp.

Here is an example application that sets up the standard test-spec.war webapp from the distribution in embedded fashion. It can be found in the jetty git repository in the examples/embedded project. Note that the test-spec.war uses not only annotations, but also JNDI, so this example also enables their processing (via the org.eclipse.jetty.plus.webapp.EnvConfiguration, org.eclipse.jetty.plus.webapp.PlusConfiguration and their related jars).

Example 12.1. ServerWithAnnotations.java


See an error or something missing? Contribute to this documentation at Github!(Generated: 2015-05-18T01:01:25+00:00)