Skip to content

bazlakausar/Deploying-Web-Applications-in-Jetty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Deploying-Web-Applications-in-Jetty

  • We'll start with a quick review of the Jetty web server before moving on to different methods for deploying a WAR file.

1) SETUP

  • 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

    2

  • 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

    3

    4

    • After executing this command jetty-app.war will be created at location jetty-app/target/jetty-app.war.

      5

2) JETTY STRUCTURE

123

3) USING WAR (Deploying web application by copying WAR)

  • 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.

6

  • Hello world! should appear on the screen if we navigate to the URL given below in the web browser.

    http://localhost:8080/jetty-app

7

4) USING JETTY MAVEN PLUGIN (Deploying web application by using jetty maven plugin)

  • 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

8

9

  • 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

10

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published