Jetty Basics

Jetty is a Java HTTP (Web) server and Java Servlet container.

In this tutorial you will learn how to deploy a web application packaged as a .war file in Jetty.


Prerequisite:

You are not required (but recommended) to do the Git Basics Tutorial.

  • However, ensure that you have Git client installed in your machine.


Install Jetty

  1. Go to Jetty's download page. Download the appropriate version.

    Jetty is highly dependent on the installed JDK. Make sure that your version of JDK is compatible with the Jetty version you will download. You may refer to the Jetty Comparison Table for Jetty-JDK version compatibility.


  2. Extract Jetty in a directory. We will call this directory as Jetty's home directory.

  3. Open a terminal window a go to the Jetty directory.

  4. Start the Jetty server.

    java -jar start.jar
    

    Output:

    :
    :
    2016-01-20 16:16:04.688:INFO:oejs.ServerConnector:main: Started ServerConnector@380fb434{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
    2016-01-20 16:16:04.689:INFO:oejs.Server:main: Started @2121ms
    

    Just in case you encounter an error in running Jetty, you may need to edit start.ini and include the following line: -Dorg.apache.jasper.compiler.disablejsr199=true

    If this still does not work, remove the said line and check the Internet for possible solution.


Deploy a Sample Application in Jetty

  1. Open another terminal window. Clone the git repository https://github.com/pong-pantola/jetty-basics.git and go to the created jetty-basics directory.

    > git clone https://github.com/pong-pantola/jetty-basics.git
    > cd jetty-basics
    

    A sample web application calcuapp.war can be found in the directory. This sample application simply displays 3 simple mathematical equations.


  2. Copy calcuapp.war to Jetty's webapps subdirectory.

  3. On a web browser, go to http://localhost:8080/calcuapp/calculator.jsp.

    Output:

    5 + 9 = 14
    8 - 2 = 6
    4 x 7 = 28 
    

    You have successfully deployed the calculator application in Jetty.


  4. Delete calcuapp.war from Jetty's webapps subdirectory.

  5. Go back to the terminal window showing the Jetty console. Press Ctrl+C to stop the server.


End of Tutorial

Go back to the List of Tutorials.

What's next?

GitHub Basics Tutorial

Written on