Skip to content

Latest commit

 

History

History
107 lines (83 loc) · 4.21 KB

File metadata and controls

107 lines (83 loc) · 4.21 KB

Deploying Web Applications

For the purpose of deploying web applications to Jetty, there are two types of resources that can be deployed:

  • Standard Web Application Archives, in the form of *.war files or web application directories, defined by the Servlet specification. Their deployment is described in this section.

  • Jetty context XML files, that allow you to customize the deployment of standard web applications, and also allow you use Jetty components, and possibly custom components written by you, to assemble your web applications. Their deployment is described in this section.

Deploying *.war Files

A standard Servlet web application is packaged in either a *.war file or in a directory with the structure of a *.war file.

Note

Recall that the structure of a *.war file is as follows:

mywebapp.war
├── index.html (1)
└── WEB-INF (2)
    ├── classes/ (3)
    ├── lib/ (4)
    └── web.xml (5)
  1. Publicly accessible resources such as *.html, *.jsp, *.css, *.js files, etc. are placed in *.war or in sub-directories of the *.war.

  2. WEB-INF is a special directory used to store anything related to the web application that must not be publicly accessible, but may be accessed by other resources.

  3. WEB-INF/classes stores the web application compiled *.class files

  4. WEB-INF/lib stores the web application *.jar files

  5. WEB-INF/web.xml is the web application deployment descriptor defines the components and the configuration of your web application.

To deploy a standard web application, you need to enable the deploy module (see the deploy module complete definition here).

$ java -jar $JETTY_HOME/start.jar --add-module=deploy
link:jetty[role=include]

The deploy module creates the $JETTY_BASE/webapps directory, the directory where *.war files or web application directories should be copied so that Jetty can deploy them.

Note

The deploy module only provides the feature of deploying web applications.

Whether these web applications are served via clear-text HTTP/1.1, or secure HTTP/1.1, or secure HTTP/2, or HTTP/3 (or even all of these protocols) depends on whether the correspondent Jetty modules have been enabled. Refer to the section about protocols for further information.

Now you need to copy a web application to the $JETTY_BASE/webapps directory, and you can use one of the demos shipped with Jetty:

$ java -jar $JETTY_HOME/start.jar --add-module=demo-simple

The $JETTY_BASE directory is now:

$JETTY_BASE
├── resources
│   └── jetty-logging.properties
├── start.d
│   ├── deploy.ini
│   └── http.ini
└── webapps
    └── demo-simple.war

Now start Jetty:

$ java -jar $JETTY_HOME/start.jar
link:jetty[role=include]

Note the highlighted line that logs the deployment of demo-simple.war.

Now you can access the web application by pointing your browser to http://localhost:8080/demo-simple.

Advanced Deployment

If you want to customize the deployment of your web application, for example by specifying a contextPath different from the file/directory name, or by specifying JNDI entries, or by specifying virtual hosts, etc. read this section.