Jetty Server For Mac

HowToDoInJava / Spring Boot / Spring Boot – Configure Jetty Server

This tutorial describes the Eclipse Jetty Server. Jetty is a web container. It has the following core components. Servlet Container. The current version of Jetty is Jetty 9 which supports the Servlet API 3.1. Originally developed by software engineer Greg Wilkins, Jetty was originally an HTTP server component of Mort Bay Server. It was originally called IssueTracker (its original application) and then MBServler (Mort Bay Servlet server). Neither of these were much liked, so Jetty was finally picked.

By default, Spring boot uses embedded tomcat server to run the application. At times, you may need to use jetty server in place of tomcat server. Spring Boot provides Tomcat and Jetty dependencies bundled together as separate starters to help make this process as easy as possible. You can use jetty with following simple steps.

Add spring-boot-starter-jetty dependency

You will need to update pom.xml and add dependency for spring-boot-starter-jetty. Also, you will need to exclude default added spring-boot-starter-tomcat dependency.

In gradle, able change can be achieved by this:

Configure Jetty Options

To override, default jetty runtime configuration – you can configure them in application.properties file.

Also, you may configure these options programatically using JettyEmbeddedServletContainerFactory bean.

MacDownload jetty server for mac

Update for Spring boot 2.0.0.RELEASE

Jetty Server For Mac

Above code snippet was valid for spring boot spanshot version. After Spring boot 2.0.0.RELEASE is available, you shall be using ConfigurableServletWebServerFactory and JettyServletWebServerFactory classes.

Drop me your questions in comments section related to using jetty in stead of tomcat server in any spring boot application.

Happy Learning !!

Jetty

Ref: Configure Jetty

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.
TwitterFacebookLinkedInRedditPocket

PROBLEM

Jetty Server For Mac

In order to run our web application using HTTPS, we need to enable SSL first on Jetty.

SOLUTION #1: Generating Certificate on the Fly

One clean solution by @PascalThivent is to recreate the certificate whenever Jetty starts. Not to steal any credits from him, but here’s a slightly modified configuration using more recent plugin versions:-

In this case, the generated certificate is stored under the project’s build directory (“target” directory) every time we run mvn clean jetty:run. This is a great solution because it allows me to easily pass my project to my peers without the need to worry about the generated certificate.

However, a downside to this approach is because the certificate is regenerated again and again, my browser keeps prompting me to add an exception whenever I refresh the web link.

… and after adding the exception for like 5 times, it begins to get very annoying.

Jetty Server For Mac Windows 10

SOLUTION #2: Generating Certificate Once and Reuse it

Instead of regenerating the certificate again and again, I decided to generate the certificate that will last for 99999 days and store it under src/main/config directory.

Jetty Server For Mac High Sierra

To generate (or regenerate) the certificate, run mvn keytool:clean keytool:generateKeyPair.

Jetty Server For Mac Os

With this approach, I just need to add an exception ONCE in my browser regardless of the number of times I restart Jetty… or when I’m still actively working on this project after 99999 days.