Jetty

Also known as: Eclipse Jetty

On this page 7

Jetty, also known as Eclipse Jetty, is an open-source Java web server and servlet container that serves HTTP traffic and runs Java web applications built on the Jakarta Servlet specification. Among web servers it stands out because it is designed to be embedded inside an application as a library rather than installed only as a standalone daemon, which makes it a common building block on Java servers.

Jetty is maintained under the Eclipse Foundation and supports HTTP/1.1, HTTP/2, HTTP/3 and WebSocket. It appears in build tools, IDEs, data platforms and microservices, often without users realizing that a Jetty instance is answering their requests.

How Jetty handles HTTP requests

Jetty processes requests through a chain of connectors, a thread pool and handlers. A connector listens on a network port, accepts TCP or QUIC connections and parses the protocol, while a handler tree decides what to do with each request, for example serving a static file, applying a rewrite rule or passing control to a servlet.

The I/O core is asynchronous and non-blocking, built on Java NIO selectors. A connection that is idle does not occupy a thread, so a single Jetty instance can keep tens of thousands of open connections while using a bounded thread pool. Threads are borrowed only when there is work to do, such as reading a request body or running application code.

The main architectural building blocks are summarized below.

ComponentRoleTypical configuration
ServerTop-level container that owns everything elseOne per JVM process in most deployments
ConnectorAccepts connections and decodes the protocolHTTP on 8080, TLS on 8443, HTTP/2 or HTTP/3 factories
QueuedThreadPoolSupplies worker threads for request processingRoughly 8 to 200 threads, tuned to workload
HandlerProcesses or routes a requestContext, resource, rewrite and gzip handlers
ServletContextHandlerHosts servlets and filters for one context pathOne per web application or API
WebAppContextDeploys a full WAR file with its descriptorUsed in standalone, Tomcat-style setups
Core components of a Jetty server

Embedded and standalone deployment modes

Jetty can run in two distinct ways, and the choice shapes how an application is built and operated. In embedded mode, the application includes Jetty as a dependency, creates a Server object in its main method and starts it, so the application owns the server. In standalone mode, administrators unpack the Jetty distribution, configure modules in a jetty-base directory and deploy WAR files into it, so the server owns the applications.

Embedded use dominates modern practice because it fits self-contained executable JAR files, container images and twelve-factor style services. Spring Boot, for example, can use Jetty as its embedded server instead of the default Apache Tomcat with a dependency change.

AspectEmbedded modeStandalone mode
StartupStarted from application codeStarted by the start.jar launcher
ConfigurationJava code or framework propertiesModule files and XML in jetty-base
PackagingSingle executable JAR or imageWAR files deployed into the server
UpgradesRebuild the applicationReplace jetty-home, keep jetty-base
Best fitMicroservices and toolsSeveral legacy WAR applications on one host
Comparison of Jetty deployment modes

Jetty belongs to the family of Java servlet containers, so its closest neighbor is Apache Tomcat, while general-purpose web servers such as Nginx and Apache HTTP Server solve a different problem. Nginx cannot run Java code itself; it typically sits in front of Jetty as a reverse proxy that terminates TLS, caches static assets and balances load.

The following comparison highlights where Jetty fits among common server technologies.

ServerPrimary languageMain strengthTypical role
JettyJavaSmall footprint and easy embeddingEmbedded server in Java applications
Apache TomcatJavaMature reference-style servlet containerStandalone or embedded Java web server
UndertowJavaLightweight non-blocking coreEmbedded server in WildFly and Quarkus setups
NginxCVery efficient static serving and proxyingEdge proxy in front of application servers
GunicornPythonSimple pre-fork WSGI servingApplication server for Python frameworks
Jetty and neighboring server technologies

Jetty is not a full application server in the Jakarta EE sense. It implements the Servlet, WebSocket and JSP pieces but does not provide EJB, JTA or full messaging stacks, which keeps it lean and fast to start.

Versions and specification support

Each major Jetty version targets a specific Java baseline and servlet generation, so version selection is a compatibility decision. The move from the javax.servlet namespace to jakarta.servlet is the most important break: applications compiled against the old namespace need Jetty 9.4 or the EE8 environment, or a migration of their imports.

Jetty versionMinimum JavaServlet supportStatus
Jetty 9.4Java 8Servlet 3.1, javax namespaceEnd of community support
Jetty 10Java 11Servlet 4.0, javax namespaceEnd of community support
Jetty 11Java 11Servlet 5.0, jakarta namespaceEnd of community support
Jetty 12Java 17EE8, EE9 and EE10 environmentsCurrent maintained line
Major Jetty release lines

Jetty 12 introduced a redesigned core in which servlet support is an optional layer. The same server can host applications for several Jakarta EE generations side by side, and lightweight services can run on the core handler API with no servlet container at all.

Tuning, security and common pitfalls

Most production problems with Jetty come from thread pool sizing, timeouts and outdated versions rather than from the server design. Because Jetty is frequently hidden inside another product, teams often run an unpatched embedded Jetty without knowing it, which has made Jetty vulnerabilities a recurring item in dependency scanning reports.

SymptomLikely causeRecommended fix
Requests queue under loadThread pool too small for blocking codeRaise maxThreads or move blocking calls off request threads
Connections dropped after 30 sIdle timeout shorter than client behaviorAlign idleTimeout with proxy and client timeouts
Large uploads rejectedForm or request size limitsAdjust maxFormContentSize or use multipart limits
Scanner flags old CVEsOutdated embedded Jetty dependencyUpgrade to a maintained Jetty 12 release
ClassNotFound for javax.servletNamespace mismatch after upgradeUse the EE8 environment or migrate to jakarta
Frequent Jetty problems and their fixes
  • Terminate TLS deliberately: either in Jetty with a modern cipher configuration or at a reverse proxy, never inconsistently in both.
  • Disable directory listing and remove default context handlers in production.
  • Set request header size limits to reduce exposure to oversized header attacks.
  • Track the Jetty version inside every product that embeds it, not only in your own code.

In everyday language

Jetty is a piece of software that lets a Java program talk to web browsers and other programs over the internet. When someone opens a page, Jetty receives the request, hands it to the right part of the program and sends the answer back.

What makes it special is that Jetty can live inside the program itself. Instead of setting up a separate web server and installing an application on it, developers can simply include Jetty, much like adding a built-in engine to a vehicle rather than towing it behind. The key idea is a small, embeddable web server for Java.

Seen in the real world

A logistics company runs a fleet-tracking API written in Java. The team packages each service as a container image that contains a single executable JAR with embedded Jetty 12, listening on port 8080 behind an Nginx reverse proxy that handles TLS and rate limiting. Each container uses a thread pool of 200 threads and an idle timeout of 60 seconds to match the proxy configuration.

During a quarterly dependency scan, the security team also finds an old Jetty 9.4 library inside a third-party reporting tool. They upgrade the tool to a release built on a maintained Jetty line, and the API services handle peak traffic of about 3,000 requests per second with stable latency and no unpatched server components.