OSGi-enabled WebApp Component
You can create an OSGi-enabled web application by selecting the implementation type as a Plugin Project. When the web application is OSGi-enabled, a web.xml file is packaged in the OSGi plug-in. The advantages of creating an OSGi-enabled WebApp component are:
- Loads all the resources from the Implementation Bundle (OSGi-enabled WebApp) using the Implementation Bundle Class Loader instead of the Component Bundle Class Loader.
- Removes the overhead of exporting all the resources from the Implementation Bundle (which require user inference and is error prone).
- Behaves as a self-justifying bundle where all the dependencies can be specified in its own MANIFEST.MF file instead of specifying them in the component's .requirement file.
Structure of Bundle
The WebApp component is composed as a set of OSGi bundles. OSGi bundles are JAR files that typically contain Java class files of the service interfaces, their implementation, and some meta information in a META-INF/manifest.mf file. Services are Java interfaces. After the bundle is registered as a service with the OSGi framework, other bundles can use the "published" service. You can add Servlets, References, and properties if required. The Servlets and all static content (HTML, JPEG files, and so on) reside in Java plug-ins.
The typical directory structure is shown below:
- Static resources such as HTML files or image files can directly be placed in the WebContent directory or in a sub-directory.
- All dependencies of the Implementation Bundle needs to be specified in its own MANIFEST.MF file instead of a .requirement file.
- The WebApp component has a require-bundle dependency to its implementation.
Web.xml File
The web.xml file is generated using a Generate Servlet Implementation wizard. This wizard generates a default web.xml. Using any other existing web.xml is not allowed. The default values in web.xml are inline with the Generate WTP Wizard provided by Eclipse. The default web.xml is of version 2.4. Selecting different versions of web.xml while generating the implementation is not supported. If required, you need to manually change the version of web.xml. Supported versions are 2.4, 2.5, 3.0, and 3.1.