Using JNDI with Jetty Embedded

Setting up the Classpath

In addition to the jars that you require for your application, and the jars needed for core Jetty, you will need to place the following jars onto your classpath:

jetty-jndi.jar
jetty-plus.jar

If you are using transactions, you will also need the javax.transaction api.
You can obtain this jar here.

If you wish to use mail, you will also need the javax.mail api and implementation which you can download here.
Note that this jar also requires the javax.activation classes, which is available at this link.

Example Code

Here is an example class that sets up some JNDI entries and deploys a webapp that references these JNDI entries in code.
We’ll use some mocked up classes for the transaction manager and the DataSource in this example for simplicity: