Web Fragment Projects

You can modularize your Web application deployment descriptor by using Web Fragment projects.  This pages provides the necessary information on how to use them.

This feature is available in MyEclipse.

By using Web Fragment projects, your Web application deployment descriptor can be modularized just as you are able to modularize your applications. Each Web Fragment project contains a web-fragment.xml descriptor that defines the artifacts for the module without requiring you to edit the Web application’s web.xml descriptor. The web fragment descriptors included in a Web application complete the web.xml descriptor.

Web fragment descriptors include the same information as web.xml with the following additional requirements:

  • The top level element must be <web-fragment>
  • The web fragment descriptor file must be named web-fragment.xml


Sample web-fragment.xml file

When you create a Web Fragment project, you can include it in an existing Web project. When you select this option, the Web Fragment project is automatically added to the Web project’s deployment assembly. You can always include one or more Web Fragment projects in a Web application by adding them to the Web project’s deployment assembly.

The image below presents an annotated view of the structure of a Web Fragment project that is included in a Web project. In the Web Fragment project, you see the web-fragment.xml descriptor in the src/META-INF folder. In the Web project, you see that the libraries from the Web Fragment project are referenced.


Example project file structure

While the actual name of the src folder and its location within the project are user-definable, its subfolder structure must include the layout shown  below.

<project src>
META-INF/
web-fragment.xml

ElementsDescription
src

The source folder that contains packages and class files.

META-INF/

A direct child folder of the src folder. This folder must contain the web fragment descriptor file.

web-fragment.xml

The Java EE web fragment deployment descriptor that defines the Java EE web entities such as servlets and tag libraries. This file is required by Java EE web fragment projects for deployment and execution. The web-fragment.xml file resides in the src/META-INF folder, and the filename is required to be web-fragment.xml. MyEclipse interprets and maintains this file.

Additionally, MyEclipse includes two special project members, the .settings folder and the .myeclipse folder. The .settings folder Holds all project settings. This folder should be treated with equal importance as the project’s corresponding Eclipse .project and .classpath files. If you are maintaining your project within a source management system, e.g., CVS,  include the .settings folder under version control.

The .myeclipse folder is MyEclipse’s transient work area for storing temporary data such as compiled JSPs. Because it is a temporary work area, it might be created and deleted dynamically by MyEclipse Web tools and does not appear as part of a new project. It is generated automatically only if needed by the project. You do not need to maintain this folder under your source code control system. For example, if you are maintaining your project in CVS, we recommend adding .myeclipse to the project’s .cvsignore file.

Note: The .* files and folders might not be visible in your project. You must choose to view them using the Explorer filtering.