# Jetty — Lightweight Embeddable Java Web Server > Eclipse Jetty is a high-performance HTTP server and servlet container that can be embedded into Java applications or run standalone, supporting HTTP/2, HTTP/3, and WebSocket. ## Install Save in your project root: # Jetty — Lightweight Embeddable Java Web Server ## Quick Use ```java // Embedded Jetty server in 5 lines Server server = new Server(8080); server.setHandler(new AbstractHandler() { public void handle(String target, Request baseRequest, HttpServletRequest req, HttpServletResponse resp) { resp.setStatus(200); resp.getWriter().println("Hello from Jetty"); baseRequest.setHandled(true); } }); server.start(); ``` ## Introduction Eclipse Jetty is a Java-based web server and servlet container used in production by thousands of organizations. Its embeddable design means you can start a full HTTP server from a `main()` method with a few lines of code, avoiding the overhead of deploying WAR files to an external container. Jetty also runs as a standalone distribution for traditional deployments. ## What Jetty Does - Serves HTTP/1.1, HTTP/2, and HTTP/3 (QUIC) traffic with a unified handler API - Implements the Jakarta Servlet, WebSocket, and JSP specifications - Embeds directly into Java applications as a library dependency - Provides an asynchronous I/O layer built on Java NIO for high concurrency - Supports TLS, ALPN, and proxy protocols out of the box ## Architecture Overview Jetty is built around a Connector-Handler pipeline. Connectors accept network connections and negotiate protocols; Handlers process requests. Handlers can be composed into trees — a ContextHandlerCollection routes by path, a ServletHandler dispatches to servlets, and a GzipHandler compresses responses. The underlying transport layer uses an event-driven I/O model with configurable thread pools. This architecture allows Jetty to handle tens of thousands of concurrent connections on modest hardware. ## Self-Hosting & Configuration - Embed via Maven/Gradle: add `jetty-server` and `jetty-servlet` dependencies - Create a `Server` instance, attach handlers or servlets, and call `server.start()` - For standalone use, download the Jetty distribution and deploy WAR files into `$JETTY_BASE/webapps` - Configure connectors, thread pools, and TLS in `jetty.xml` or programmatically - Enable HTTP/2 by adding the `jetty-http2` module and configuring ALPN ## Key Features - Embeddable design — no external container needed, perfect for microservices - Full HTTP/2 and experimental HTTP/3 support with automatic protocol negotiation - Low memory footprint compared to full application servers - Proven at scale — used by Google App Engine, Eclipse IDE, and Jenkins - Active maintenance under the Eclipse Foundation with frequent releases ## Comparison with Similar Tools - **Tomcat** — Similar servlet container; Jetty is lighter and more embed-friendly while Tomcat is more widely used standalone - **Undertow** — Red Hat's embeddable server; Jetty has broader protocol support including HTTP/3 - **Netty** — Low-level network framework; Jetty provides servlet-level abstractions on top - **Spring Boot embedded** — Uses Tomcat, Jetty, or Undertow under the hood; Jetty is one of the pluggable options - **Nginx/Caddy** — Native reverse proxies; Jetty is a Java application server, not a general-purpose proxy ## FAQ **Q: Can I use Jetty as a reverse proxy?** A: Yes. Jetty includes a ProxyServlet and an AsyncProxyServlet for forwarding requests to upstream services. **Q: How does Jetty compare to Tomcat for Spring Boot?** A: Both work as embedded containers in Spring Boot. Jetty tends to use less memory and starts faster; Tomcat has broader community adoption. **Q: Does Jetty support Jakarta EE?** A: Jetty 12 supports both javax and jakarta namespaces through its environment abstraction, making migration seamless. **Q: What Java version does Jetty require?** A: Jetty 12 requires Java 17 or later. Jetty 11 supports Java 11+. ## Sources - https://github.com/jetty/jetty.project - https://jetty.org/docs/ --- Source: https://tokrepo.com/en/workflows/asset-eefd92c2 Author: AI Open Source