All Products
Search
Document Center

Elastic Compute Service:Deploy a Java web environment with Jetty

Last Updated:May 15, 2026

Install and configure Jetty on an ECS instance to host Java web applications in a lightweight servlet container.

Prerequisites

Your ECS instance must meet the following conditions:

Procedure

Choose a procedure based on the operating system of your ECS instance.

Linux

This topic uses Jetty 12.0.16 as an example. If you use a different version or directory, replace the version number and path accordingly.

  1. Log on to the Linux server. See Log on to a Linux instance using Workbench.

  2. Download and decompress the Jetty 12 installation package.

    Important
    • To install a different version or if the download link is invalid, visit the official Jetty website for the correct download link and replace the URL.

    • Different Jetty versions support different JDK versions. Check the official Jetty website to select a compatible Jetty version for your JDK.

      image

    wget https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/12.0.16/jetty-home-12.0.16.tar.gz --no-check-certificate
    tar -zxvf jetty-home-12.0.16.tar.gz
  3. Move the Jetty directory.

    sudo mv jetty-home-12.0.16 /usr/local/jetty/
  4. Create the jetty-base directory.

    sudo mkdir /usr/local/jetty-base
  5. Set the environment variables.

    1. Edit the ~/.bashrc file.

      sudo vim ~/.bashrc
    2. Press i to enter edit mode and add the following content to the file.

      Note

      Set JETTY_HOME to the actual Jetty installation directory and JETTY_BASE to the jetty-base directory.

      export JETTY_HOME=/usr/local/jetty
      export JETTY_BASE=/usr/local/jetty-base
    3. Press Esc, enter :wq, and press Enter to save and close the file.

    4. Apply the changes.

      source ~/.bashrc
  6. Enable the Jetty modules and initialize the jetty-base directory.

    1. Go to the jetty-base directory.

      cd /usr/local/jetty-base
    2. Initialize the jetty-base directory. This creates the $JETTY_BASE/start.d/ directory and other directories that contain server configuration.

      Note
      • To view available modules, run the java -jar $JETTY_HOME/start.jar --list-modules=* command.

      • If you use Jetty 9, replace --add-module with --add-to-start.

      sudo java -jar $JETTY_HOME/start.jar --add-module=server,http,deploy

      image

  7. Verify the deployment.

    Important

    Run the following commands in the jetty-base directory.

    1. Deploy the Jetty sample web application.

      • If you use Jetty 11 or 10, replace demos with demo in the following command.

      • If you use Jetty 9, run the sudo mv $JETTY_HOME/demo-base/webapps/ROOT $JETTY_BASE/webapps command to deploy the sample.

      Note

      You can also upload a local WAR package to the $JETTY_BASE/webapps directory for testing. See Upload or download files.

      sudo java -jar $JETTY_HOME/start.jar --add-module=demos
    2. Start Jetty.

      Note

      By default, Jetty listens on port 8080. Run sudo netstat -tunlp | grep 8080 to check if the port is in use. If so, specify a different port: nohup sudo java -jar $JETTY_HOME/start.jar jetty.http.port=8081 &.

      nohup sudo java -jar $JETTY_HOME/start.jar &
    3. In your browser, enter http://<Public IP address>:8080. If the test page appears, the deployment is successful.

      Note
      • If you changed the Jetty port, replace 8080 with the new port number and allow the new port in the security group. See Add a security group rule.

      • If you uploaded a local WAR package, access http://<Public IP address>:8080/<Package name> to test it.

      image

Windows

Important

This section applies only to Jetty 12, Jetty 11, and Jetty 10.

This topic uses Jetty 12.0.16 as an example. If you use a different version or directory, replace the version number and path accordingly.

  1. Log on to the Windows server. See Use Workbench to log on to a Windows instance.

  2. Download Jetty.

    Different Jetty versions support different JDK versions. Check the official Jetty website to select a compatible version for your JDK, then download the installation package.

    image

    image

  3. Decompress the Jetty package.

    Decompress the package to your preferred location. This topic uses C:\download as an example.

    Important

    Decompress Jetty to a path without spaces.

  4. Set the JETTY_HOME environment variable.

    1. Right-click This PC and select Properties.image

    2. On the About page, scroll to the bottom and click Advanced system settings.image

    3. Click Environment Variables.image

    4. In the System variables section, click New. Set the variable name to JETTY_HOME and the value to the Jetty installation directory, such as C:\download\jetty-home-12.0.16. Click OK.

      image

    5. Click OK to save the configuration.

  5. Create a jetty-base folder. This topic uses C:\download as an example.

    image

  6. Initialize the jetty-base folder.

    1. Go to the jetty-base folder, enter cmd in the address bar, and press Enter to open the command prompt.

      image

    2. Initialize the jetty-base folder. This creates the start.d directory and other directories that contain server configuration.

      java -jar %JETTY_HOME%/start.jar --add-module=http,server,deploy

      image

  7. Verify the deployment.

    1. Deploy the Jetty sample web application.

      If you use Jetty 11 or 10, replace demos with demo in the following command.

      Note

      You can also upload a local WAR package to the <jetty-base>/webapps directory for testing. <jetty-base> is the path to the jetty-base folder, such as C:\download\jetty-base. See Upload or download files.

      java -jar %JETTY_HOME%/start.jar --add-module=demos
    2. Start Jetty. Do not close the command prompt window after Jetty starts.

      Note

      By default, Jetty listens on port 8080. Run netstat -ano | findstr :8080 to check if the port is in use. If so, specify a different port: java -jar %JETTY_HOME%/start.jar jetty.http.port=8081.

      java -jar %JETTY_HOME%/start.jar
    3. In your browser, enter http://<Public IP address>:8080. If the test page appears, the deployment is successful.

      Note
      • If you changed the Jetty port, replace 8080 with the new port number and allow the new port in the security group. See Add a security group rule.

      • If you uploaded a local WAR package, access http://<Public IP address>:8080/<Package name> to test it.

      image

Next steps

  • Configure a website on the server and associate a domain name with the public IP address of the instance. See Build a website.

    If your application needs a database, add the database configuration to your web project configuration files, such as a Properties file. After development, deploy the WAR package to the $JETTY_BASE/webapps directory and start Jetty to access your application. For more details, visit the official Jetty website.

    Note

    If you use a different Jetty version, replace the version number in the URL.

    To upload local files to an ECS instance, see Upload or download files (Linux).

    To use a database, use ApsaraDB RDS for MySQL or deploy a MySQL database on your instance.

  • Use Server Load Balancer (SLB) to improve the availability and performance of your website.

FAQ

After deployment, I cannot access http://<Public IP address>:8080 from my local browser

After deploying Jetty, you might be unable to access http://<Public IP address>:8080 from your browser. Possible causes:

  • Cause 1: Firewall or SELinux blocks access

    The system firewall or SELinux might block external access. Solutions:

  • Cause 2: Custom Jetty port

    You changed the Jetty port at startup.

    Replace 8080 in http://<Public IP address>:8080 with the new port number and allow the new port in the security group.