Convert Figma logo to code with AI

jetty logojetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more

3,825
1,907
3,825
385

Top Related Projects

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more

Spring Boot

33,257

Netty project - an event-driven asynchronous network application framework

High performance non-blocking webserver

7,476

Apache Tomcat

14,240

Vert.x is a tool-kit for building reactive applications on the JVM

Quick Overview

Jetty is a Java-based web server and servlet container developed by the Eclipse Foundation. It provides a robust and scalable platform for deploying web applications, supporting both synchronous and asynchronous processing models. Jetty is known for its lightweight footprint and high performance, making it suitable for embedding in applications or using as a standalone server.

Pros

  • Lightweight and highly customizable
  • Excellent performance and scalability
  • Supports both servlet and websocket specifications
  • Easy to embed in Java applications

Cons

  • Steeper learning curve compared to some alternatives
  • Less extensive documentation compared to more popular servers like Tomcat
  • Smaller community and ecosystem compared to some competitors
  • Configuration can be complex for advanced use cases

Code Examples

  1. Embedding Jetty in a Java application:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;

public class EmbeddedJettyExample {
    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        
        ServletHandler handler = new ServletHandler();
        server.setHandler(handler);
        
        handler.addServletWithMapping(HelloServlet.class, "/*");
        
        server.start();
        server.join();
    }
}
  1. Configuring SSL/TLS:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;

public class SslJettyExample {
    public static void main(String[] args) throws Exception {
        Server server = new Server();
        
        SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
        sslContextFactory.setKeyStorePath("/path/to/keystore");
        sslContextFactory.setKeyStorePassword("password");
        
        ServerConnector sslConnector = new ServerConnector(server, sslContextFactory);
        sslConnector.setPort(8443);
        
        server.addConnector(sslConnector);
        
        server.start();
        server.join();
    }
}
  1. Setting up a WebSocket endpoint:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;

public class WebSocketExample {
    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        server.setHandler(context);
        
        JettyWebSocketServletContainerInitializer.configure(context, (servletContext, wsContainer) ->
            wsContainer.addEndpoint(MyWebSocketEndpoint.class)
        );
        
        server.start();
        server.join();
    }
}

Getting Started

To get started with Jetty, add the following dependency to your Maven pom.xml:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-server</artifactId>
    <version>11.0.13</version>
</dependency>

For Gradle, add this to your build.gradle:

implementation 'org.eclipse.jetty:jetty-server:11.0.13'

Then, you can create a simple server using the following code:

import org.eclipse.jetty.server.Server;

public class SimpleJettyServer {
    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        server.start();
        server.join();
    }
}

This will start a basic Jetty server on port 8080.

Competitor Comparisons

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more

Pros of jetty.project

  • Established and widely-used Java web server and servlet container
  • Extensive documentation and community support
  • Highly configurable and customizable

Cons of jetty.project

  • Learning curve can be steep for beginners
  • May be overkill for simple web applications
  • Regular updates and maintenance required

Code Comparison

Both repositories contain the same codebase, as they are the same project. Here's a sample from the Server.java file:

public class Server extends HandlerWrapper implements Graceful
{
    private static final Logger LOG = Log.getLogger(Server.class);

    private final ShutdownMonitor shutdownMonitor;
    private final Container _container = new Container();

Summary

As the repositories jetty.project and jetty.project are identical, there are no differences to compare. Jetty is a popular Java HTTP server and servlet container, known for its flexibility and performance. It offers a robust set of features for building web applications but may require some time to master for newcomers to the platform.

Spring Boot

Pros of Spring Boot

  • Provides a comprehensive, opinionated framework for rapid application development
  • Offers auto-configuration and starter dependencies for easy setup
  • Includes built-in production-ready features like metrics and health checks

Cons of Spring Boot

  • Can be overkill for simple applications or microservices
  • Steeper learning curve for developers new to the Spring ecosystem
  • May have slower startup times compared to lightweight alternatives

Code Comparison

Spring Boot application setup:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Jetty server setup:

Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
server.start();
server.join();

Spring Boot focuses on providing a complete application framework with minimal configuration, while Jetty is primarily a servlet container and web server. Spring Boot abstracts away much of the server setup, whereas Jetty requires more explicit configuration. Spring Boot is better suited for full-fledged applications, while Jetty is often used as an embedded server or for simpler web applications.

33,257

Netty project - an event-driven asynchronous network application framework

Pros of Netty

  • More flexible and customizable architecture
  • Better performance for high-concurrency scenarios
  • Broader protocol support, including custom protocols

Cons of Netty

  • Steeper learning curve due to its flexibility
  • Less out-of-the-box functionality compared to Jetty
  • Requires more manual configuration for basic setups

Code Comparison

Jetty (Servlet-based HTTP server):

Server server = new Server(8080);
ServletHandler handler = new ServletHandler();
server.setHandler(handler);
handler.addServletWithMapping(HelloServlet.class, "/*");
server.start();

Netty (Custom HTTP server):

EventLoopGroup group = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(group)
 .channel(NioServerSocketChannel.class)
 .childHandler(new HttpServerInitializer());
b.bind(8080).sync();

Both Jetty and Netty are popular Java networking frameworks, but they serve different purposes. Jetty is primarily a servlet container and web server, while Netty is a more general-purpose networking framework. Netty offers greater flexibility and performance for complex networking applications, but comes with a steeper learning curve. Jetty provides a more straightforward setup for traditional web applications and servlets.

High performance non-blocking webserver

Pros of Undertow

  • Lightweight and highly performant, with lower memory footprint
  • Designed for both blocking and non-blocking IO, offering greater flexibility
  • Simpler API and easier to embed in applications

Cons of Undertow

  • Smaller community and ecosystem compared to Jetty
  • Less comprehensive documentation and fewer examples available
  • Limited built-in features, requiring additional libraries for some functionalities

Code Comparison

Undertow server setup:

Undertow server = Undertow.builder()
    .addHttpListener(8080, "localhost")
    .setHandler(new HttpHandler() {
        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            exchange.getResponseSender().send("Hello World");
        }
    }).build();
server.start();

Jetty server setup:

Server server = new Server(8080);
server.setHandler(new AbstractHandler() {
    @Override
    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.getWriter().println("Hello World");
        baseRequest.setHandled(true);
    }
});
server.start();

Both examples demonstrate a simple HTTP server setup, but Undertow's API is more concise and uses a builder pattern, while Jetty follows a more traditional approach with explicit server and handler configuration.

7,476

Apache Tomcat

Pros of Tomcat

  • More extensive documentation and larger community support
  • Broader range of features and configurations out-of-the-box
  • Better integration with other Apache projects

Cons of Tomcat

  • Heavier resource footprint, potentially slower startup times
  • More complex configuration and deployment process
  • Less suitable for embedded applications

Code Comparison

Tomcat's web.xml configuration:

<web-app>
  <servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>com.example.MyServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/myservlet</url-pattern>
  </servlet-mapping>
</web-app>

Jetty's web.xml configuration:

<web-app>
  <servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>com.example.MyServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/myservlet</url-pattern>
  </servlet-mapping>
</web-app>

Both Tomcat and Jetty use similar web.xml configurations, but Jetty tends to have more programmatic configuration options, making it more flexible for embedded use cases.

14,240

Vert.x is a tool-kit for building reactive applications on the JVM

Pros of Vert.x

  • Reactive and event-driven architecture, offering better scalability for high-concurrency scenarios
  • Polyglot support, allowing developers to write applications in multiple programming languages
  • Built-in clustering and distributed event bus for easier microservices development

Cons of Vert.x

  • Steeper learning curve due to its reactive programming model
  • Smaller community and ecosystem compared to Jetty
  • Less mature and battle-tested in production environments

Code Comparison

Jetty (Servlet-based):

public class HelloServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().println("Hello, World!");
    }
}

Vert.x:

public class HelloVerticle extends AbstractVerticle {
    @Override
    public void start() {
        vertx.createHttpServer().requestHandler(req -> {
            req.response().end("Hello, World!");
        }).listen(8080);
    }
}

The code comparison shows the difference in approach between Jetty's traditional servlet-based model and Vert.x's event-driven, non-blocking model. Vert.x's code is more concise and focuses on handling events, while Jetty follows the standard servlet lifecycle.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Eclipse Jetty

Eclipse Jetty is a lightweight, highly scalable, Java-based web server and Servlet engine. Jetty's goal is to support web protocols (HTTP/1, HTTP/2, HTTP/3, WebSocket, etc.) in a high volume low latency way that provides maximum performance while retaining the ease of use and compatibility with years of Servlet development. Jetty is a modern fully asynchronous web server that has a long history as a component oriented technology, and can be easily embedded into applications while still offering a solid traditional distribution for webapp deployment.

Webapp Example

$ mkdir jetty-base && cd jetty-base
$ java -jar $JETTY_HOME/start.jar --add-modules=http,ee10-deploy
$ cp ~/src/myproj/target/mywebapp.war webapps
$ java -jar $JETTY_HOME/start.jar 

Multiple Versions Webapp Example

$ mkdir jetty-base && cd jetty-base
$ java -jar $JETTY_HOME/start.jar --add-modules=http,ee10-deploy,ee8-deploy
$ cp ~/src/myproj/target/mywebapp10.war webapps
$ cp ~/src/myproj/target/mywebapp8.war webapps
$ echo "environment: ee8" > webapps/mywebapp8.properties
$ java -jar $JETTY_HOME/start.jar 

Embedded Jetty Example

Server server = new Server(port);
server.setHandler(new MyHandler());
server.start();

Embedded Servlet Example

Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler("/");
context.addServlet(MyServlet.class, "/*");
server.setHandler(context);
server.start();

Building Jetty from Source

$ git clone https://github.com/jetty/jetty.project.git
$ cd jetty.project
$ mvn -Pfast clean install # fast build bypasses tests and other checks

For more detailed information on building and contributing to the Jetty project, please see the Contribution Guide.

Documentation

Jetty's documentation is available on the Eclipse Jetty website.

The documentation is divided into three guides, based on use case:

  • The Operations Guide targets sysops, devops, and developers who want to install Eclipse Jetty as a standalone server to deploy web applications.

  • The Programming Guide targets developers who want to use the Eclipse Jetty libraries in their applications, and advanced sysops/devops that want to customize the deployment of web applications.

  • The Contribution Guide targets developers that wish to contribute to the Jetty Project with code patches or documentation improvements.

Commercial Support

Expert advice and production support of Jetty are provided by Webtide.