Jetty Logo
Version: 9.2.2-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

Using Annotations with Jetty Embedded

Setting up the Classpath
Example

Setting up the Classpath

You will need to place the following jetty jars onto the classpath of your application. You can obtain them from the jetty distribution, or the maven repository:

You will also need the asm jar, which you can obtain from the Jetty dependencies site.

Example

Here's an example application that sets up a Jetty server, does some setup to ensure that annotations are scanned and deploys a webapp that uses annotations. This example also uses the @Resource annotation which involves JNDI, so we would also add the necessary jndi jars to the classpath., and we also add in the configuration classes that are responsible for JNDI (see line 19).

Here is the embedding code:

On line 19 we add in the configuration classes responsible for setting up JNDI and java:comp/env.

On line 20 we add in the configuration class that ensures annotations are inspected.

On lines 30, 33 and 37 we set up some JNDI resources that we will be able to reference with @Resource annotations.

With the setup above, we can create a servlet that uses annotations and Jetty will honour the annotations when the webapp is deployed:

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-07-29T01:00:23-07:00)