Java

Creating Deployment Descriptor in a Dynamic Web Project

This article explains Creating Deployment Descriptor in a Dynamic Web Project in Eclipse JEE. Basically, a deployment descriptor is called web.xml and contains configuration information regarding a dynamic web application.

However, when we create a dynamic web project in Eclipse IDE, the web.xml file is not available by default. Therefore, we need to create this file explicitly.

Steps for Creating Deployment Descriptor in a Dynamic Web Project in Eclipse

The following steps demonstrate how to create a web.xml file.

At first, create a dynamic web project in Eclipse. In order to find, the deployment descriptor, expand the WebContent folder. Further click on the WEB-INF folder that should contain the web.xml file. As can be seen, it is not available right now.

The Project Structure in Eclipse EE
The Project Structure in Eclipse EE

In order to create web.xml, right-click on the project name and select the Java EE Tools option. Further, select Generate Deployment Descriptor Stub option. It will generate the desired web.xml file under the WebContent -> WEB-INF folder.

Generate Deployment Descriptor
Generate Deployment Descriptor

The following figure shows that our deployment descriptor is generated now.

Creating Deployment Descriptor
Creating Deployment Descriptor

In order to open the web.xml file, right-click on it and select the Open With-> Text Editor option.

Editing web.xml
Editing web.xml

The following listing shows the generated web.xml file.

The Initial web.xml File
The Initial web.xml File

As can be seen, the web.xml file contains a list of welcome files enclosed within the <web-app> tag. Basically, it indicates the default file that opens when a request for a directory arrives. Now that, we have this initial web.xml file, we can use it to configure our application. For instance, suppose we want to register the servlets and specify the URL patterns for these servlets, we can do it in this web.xml file. An example of registering a servlet is given here.



Further Reading

Servlet and its Life Cycle

Input Parameters in a Servlet

Understanding Deployment Descriptor

Creating Arrays in Java

Java Practice Exercise

JavaScript Code Examples

Callback Functions in JavaScript

Understanding HTTP Requests and Responses

Basics of Java Programming

Examples of Decision Making in Java

Flow Control Using Loops in Java

How to Create User-Defined Methods in Java

Examples of For-each Loop in Java

Method Overloading Using Java

Interfaces in Java

Leave a Reply

Your email address will not be published. Required fields are marked *