Jetty Configuration in Eclipse – 在Eclipse中配置Jetty

最后修改: 2018年 8月 21日

1. Overview


Web Applications are one of the most popular use cases of Java. Web Servers and Servlet Containers provide the runtime for deploying applications.


Unfortunately, deploying and troubleshooting web applications on Web Servers is at times complicated. Luckily, IDEs have good debugging support for most applications. However, to debug web applications, we need to embed a Web Server in the IDE.


In this tutorial, we’ll embed Jetty in Eclipse and run and debug an application on it.


2. Eclipse Jetty Plugin

2.Eclipse Jetty Plugin

The simplest way of connecting Jetty to Eclipse is using the Eclipse Jetty Plugin.

连接Jetty和Eclipse的最简单方法是使用Eclipse Jetty插件。

The plugin adds a managed Jetty server into Eclipse. Hence, it allows us to deploy and test or debug applications seamlessly. Also, the plugin provides an interface for easily configuring the server.


The quickest way to install the plugin is through the Marketplace. In eclipse, the Marketplace enables us to install plugins with a few clicks:



3. Sample Application


Let’s now develop a simple web application.


First, let’s add the web.xml in the /src/main/webapp/WEB-INF folder of our project:


<web-app xmlns=""



Let’s add a simple static file. In our case, the helloworld.html looks like this:


<!DOCTYPE html>
      <meta charset="ISO-8859-1">
      <title>Hello World</title>
   <body>Hello World!</body>

Note that we haven’t added any servlet mapping to our web.xml.


Instead, we are going to use Servlet 3 annotations for our servlet:

相反,我们要为我们的Servlet使用Servlet 3注解。

public class HelloWorldServlet extends HttpServlet

WebServlet annotation enables our servlet class to be scanned and deployed on the container.


We should keep in mind that Jetty doesn’t support annotations with the basic HTTP module. Hence we’ll need to add the annotation support module for this to work.


We’ll see how to do this in the following sections.


4. Running the Application on Jetty


Deploying web application on servers varies from vendor to vendor. The Eclipse Jetty plugin takes care of this process for us. Likewise, it integrates with our IDE debugger, improving the development experience.

在服务器上部署Web应用程序,各厂商的做法不尽相同。Eclipse Jetty插件为我们处理了这个过程。同样地,它与我们的IDE调试器集成,改善了开发体验。

Sometimes we need to run the application with some configuration. Eclipse allows us to do that using the Launch Configuration.

有时我们需要用一些配置来运行应用程序。Eclipse允许我们使用 “启动配置 “来做到这一点。

This is how it looks for running applications on Jetty:


Launch config

We can configure the following parameters for our application:


  • Context Path – prefix for our application URL
  • HTTP Port – port on which the application is deployed, the default is 8080
  • Enable HTTPS – for deploying on HTTPS along with HTTP
  • HTTPS Port – default is 8443

As with regular Jetty, Eclipse Jetty plugin allows us to manage dependencies for an application before deploying. For a maven application, we could select the dependency scope as classpath if we wish to provide those from the server.

与普通的Jetty一样,Eclipse Jetty插件允许我们在部署前管理应用程序的依赖性。对于一个maven应用程序,如果我们希望从服务器上提供这些,我们可以选择依赖范围作为classpath。

5. Jetty Server Options


Jetty is a highly configurable Servlet Container. There are various parameters we can specify like Thread Pool Size, Shutdown Interval etc.


Besides that, Jetty allows us to add various Modules on top of the basic HTTP Module. These are some of the common modules we can add:


  • Annotations Support – enables support for Servlet specific annotations
  • JNDI Support – allows JNDI resource management by Jetty
  • Websocket Support – enables Websocket server and client implementations
  • JMX Support – allows monitoring of Jetty using any MBeans browser
  • JSP Support – enables JSP compiling and deployment in Jetty

These configurations are possible in Eclipse Jetty as well.  Hence, we can configure the server parameters and modules from the launch configuration.

这些配置在Eclipse Jetty中也是可行的。 因此,我们可以从启动配置中配置服务器参数和模块。

Lastly, Eclipse Jetty 4.0 plugin comes with an embedded Jetty 9.3 server. However, we can configure an external jetty server for our application from the launch configuration.

最后,Eclipse Jetty 4.0插件带有一个嵌入式Jetty 9.3服务器。然而,我们可以在启动配置中为我们的应用程序配置一个外部的jetty服务器。

6. Eclipse Jetty Console

6.Eclipse Jetty 控制台

Eclipse Jetty provides a console with some useful control commands.  This console comes in handy to manage the server or gather some metrics from the server.

Eclipse Jetty提供了一个带有一些有用控制命令的控制台。 这个控制台在管理服务器或从服务器上收集一些指标时很方便。

The console needs to be enabled in the launch configuration. When enabled, we can execute the control commands from Eclipse Console.

控制台需要在启动配置中启用。启用后,我们可以从 Eclipse 控制台执行控制命令。

Here is a list of some common commands we can use:


  • Memory – memory information of the current application
  • Threads – thread dump of the running application
  • Restart – restarts the running application
  • Stop – gracefully stops the server and all the apps running on it

7. Conclusion


Eclipse Jetty plugin is a great way of quickly running or debugging an application by embedding the Jetty server. It also allows us to configure our application and the underlying Jetty server.

Eclipse Jetty插件是一种通过嵌入Jetty服务器来快速运行或调试应用程序的好方法。它还允许我们配置我们的应用程序和底层的Jetty服务器。

In this tutorial, we installed the Eclipse Jetty plugin and deployed our application. We also created a launch configuration and provided application and server parameters.

在本教程中,我们安装了Eclipse Jetty插件并部署了我们的应用程序。我们还创建了一个启动配置并提供了应用程序和服务器参数。