Quick Guide to Embedding Jetty
| Tip | ||
|---|---|---|
| ||
For a more detailed look at embedding Jetty in your application, see the Tutorials on Embedding Jetty. |
Setting up the classpath
To run Jetty, you need only these jars:
- jetty.jar
- servlet-api-2.5.jar
- jetty-util.jar
Those jars give you the ability to serve web applications.
If you wish to use JSPs, then you will need a couple of additional jars.
JSP2.0
JSP 2.0 is used with version 2.4 of the servlet specification. Depending on the functionality you require, you may be able to use this version rather than the newer JSP2.1 jars.
| Code Block |
|---|
These are the dependencies when JSP 2.0 is used:
* ant-1.6.4.jar
* jasper-compiler-5.5.15.jar
* jasper-runtime-5.5.15.jar
* jsp-api-2.0.jar
* xercesImpl-2.6.2.jar
* commons-el-1.0.jar
* jasper-compiler-jdt-5.5.15.jar
* jcl104-over-slf4j-1.0-rc5.jar
* slf4j-simple-1.0-rc5.jar
* xmlParserAPIs-2.6.2.jar
|
JSP2.1
| Info | ||
|---|---|---|
| ||
You need to use J2SE5 (aka jdk 1.5) if you wish to use JSP2.1. |
This is the jsp version mandated by servlet specification 2.5. You will need these jars:
| Code Block |
|---|
* ant-1.6.5.jar
* core-3.1.1.jar
* jsp-2.1.jar
* jsp-api-2.1.jar
|
Code
The jetty configuration files (eg jetty.xml) have an xml syntax that is a straightforward mapping of the java API. Take a look at the files in etc/ for some hints on what calls to make in your own code. Here's the minimal code to set up a Jetty server and webapp:
| Code Block |
|---|
org.mortbay.jetty.Server server = new Server();
org.mortbay.jetty.nio.SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors (new Connector[]{connector});
WebAppContext wah = new WebAppContext();
wah.setContextPath("/myspecialapp);
wah.setWar("file:///tmp/myspecialapp.war");
server.addHandler(wah);
server.start();
|
For More Information
There are several examples of embedding Jetty in the distribution in the examples/embedded directory. Also take a look at the Tutorial on This page has moved to Embedding Jetty.