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
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.
Extract Jetty in a directory. We will call this directory as Jetty's home directory.
Open a terminal window a go to the Jetty directory.
Start the Jetty server.
java -jar start.jarOutput:
: : 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 @2121msJust 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=trueIf this still does not work, remove the said line and check the Internet for possible solution.
Deploy a Sample Application in Jetty
Open another terminal window. Clone the git repository
https://github.com/pong-pantola/jetty-basics.gitand go to the createdjetty-basicsdirectory.> git clone https://github.com/pong-pantola/jetty-basics.git > cd jetty-basicsA sample web application
calcuapp.warcan be found in the directory. This sample application simply displays 3 simple mathematical equations.Copy
calcuapp.warto Jetty'swebappssubdirectory.On a web browser, go to
http://localhost:8080/calcuapp/calculator.jsp.Output:
5 + 9 = 14 8 - 2 = 6 4 x 7 = 28You have successfully deployed the calculator application in Jetty.
Delete
calcuapp.warfrom Jetty'swebappssubdirectory.Go back to the terminal window showing the Jetty console. Press
Ctrl+Cto stop the server.
End of Tutorial
Go back to the List of Tutorials.
