- We'll start with a quick review of the Jetty web server before moving on to different methods for deploying a WAR file.
-
The very first step to start this is to download the latest version Jetty
-
Let's go to the console, navigate to our desired location, and execute the following command:
mvn archetype:generate -DgroupId=com.baeldung -DartifactId=jetty-app -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
-
This command will generate a complete Java web app in our current location's jetty-app folder. Since, WAR files are involved, so let's head to the root of the project and build it:
cd jetty-app
-
Building with Maven:
mvn package
-
To deploy a web application to a Jetty server, transfer the WAR file into $JETTY_HOME/webapps directory.
-
Navigating into $JETTY HOME and performing the command will start the server:
java -jar start.jar
-
/Jetty-app context will host our new app.
-
Hello world! should appear on the screen if we navigate to the URL given below in the web browser.
http://localhost:8080/jetty-app
-
As we build Java web applications, the jetty Maven plugin allows us to perform rapid testing and iteration.
-
Adding the plugin to pom.xml is all that's required to deploy and run applications with it:
<groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.3.11.v20160721</version>
```
-
After adding the plugin, we navigate to the root of our app and run the following command:
mvn jetty:run
-
The plugin deploys the app to a new jetty instance created by this command. We can get to it by typing the URL given below:
http://localhost:8080