An OSGi application is packaged as a JAR file, with extension '.par' for platform archive. A PAR artifact offers several benefits:
Class.forName() (or equivalent).
A PAR includes one or more application bundles and manifest specifies following manifest headers:
Table 5.1. PAR file directives
| Directive | Description |
|---|---|
| Application-SymbolicName | Identifier for the PAR which, in combination with Application-Version, uniquely identifies a PAR |
| Application-Name | Human readable name of the PAR |
| Application-Version | Version of the PAR |
| Application-Description | Short description of the PAR |
The following code shows an example MANIFEST.MF in a PAR file:
Application-SymbolicName: com.example.shop Application-Version: 1.0 Application-Name: Online Shop Application-Description: Example.com's Online Shopping Application
The most common type of application deployed in SpringSource Application Platform is, not surprisingly, the web application. The platform, therefore, supports a concept of "Web module". A Web module is an OSGi bundle whose manifest includes directives to support various options pertinent to a web application.
Web modules have the following advantages over WAR files:
Web modules are standard OSGi bundles with the following characteristics:
Table 5.2. Web module directives
| Directive | Description |
|---|---|
| Bundle-SymbolicName | Used as the 'display-name' for the web application, if the Bundle-Name is not set. It is also used as the 'description' for the web application, if the Bundle-Name and Bundle-Description are not set. |
| Bundle-Name | Used as the 'display-name' for the web application. It is also used as as the 'description' for the web application, if the Bundle-Description are not set |
| Bundle-Description | Used as the 'description' for the web application. |
| Web-ContextPath | Used as the unique context path under which the web module or WAR is deployed in the Servlet Container. Standard syntax rules apply. If not present, the file name for the bundle without the file extension will be used as the context path. |
| Web-ContextParams | Used to configure context parameters. It uses the syntax of comma-separated list of: <name>;param-value:="<value>" <name> is the name of the context parameter and <value> is the value of the named context parameter |
| Web-FilterMappings | Used to declare a Filter with a given 'filter-name'. The 'filter-class' will be set to a subclass of DelegatingFilterProxy. Thus the supplied name must map to the bean name of the corresponding Filter in the web module's ApplicationContext. For each Filter, you must configure corresponding mappings via the url-patterns directive. It uses the syntax of comma-separated list of: <name>;url-patterns:="<patterns>" where <name> is the filter bean name and <patterns> is a comma-separated list of 'url-pattern' values. The syntax of each individual value is as defined in the Servlet spec. The default value for this header is '*.htm' |
| Web-Servlets | Used to configure servlets. It has the syntax of a comma-separated list of: <name>;servlet-class:="<class>";load-on-startup:="<startup>";url-patterns:="<patterns>", where <name> is the servlet name, <class> is the fully qualified class name of the servlet, <startup> is an integer representing the "load on startup" order, and <patterns> is a comma-separated list of 'url-pattern' values for servlet mappings. The syntax of each individual value is as defined in the Servlet spec. |
| Web-DispatcherServletUrlPatterns | Used for mapping request URLs to the auto-configured DispatcherServlet for the web module. It uses the syntax of a comma-separated list of 'url-pattern' values. The syntax of each individual value is as defined in the Servlet spec. The default value for this header is '*.htm' |
| Web-SessionTimeout | Used as the 'session-timeout' value. The default value for this directive is 15 |
| Web-WelcomeFiles | Used to specify the welcome files as defined by the servlet specification. The default value for this header is 'index.jsp,index.html' |
Let's see use of these headers in an example.
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.springframework.showcase.formtags
Bundle-Version: 2.0.8
Bundle-Name: Spring Form Tags - Sample Web Application
Bundle-Description: Sample web application which demonstrates the use of Spring 2.0's
custom form tag library
Import-Package: org.springframework.osgi.web.context,
org.springframework.osgi.web.servlet,
org.springframework.showcase.formtags.domain;version="2.0.8",
org.springframework.showcase.formtags.service;version="2.0.8",
org.springframework.showcase.formtags.validation;version="2.0.8",
org.springframework.showcase.formtags.web;version="2.0.8"
Import-Library: org.springframework_all;version="2.5.3";sharing:=share
Platform-ModuleType: Web
Web-ContextPath: formtags
Web-ContextParams: javax.faces.DEFAULT_SUFFIX;param-value:=".xhtml",foo;param-value:="bar"
Web-Servlets: FacesServlet;servlet-class:="javax.faces.webapp.FacesServlet";
load-on-startup:="2";url-patterns:="*.faces",
FooServlet;servlet-class:="com.example.FooServlet";
load-on-startup:="1";url-patterns:="*.foo"
Web-DispatcherServletUrlPatterns: *.htm
Web-FilterMappings: securityFilter;url-patterns:="*.htm,*.jsp",
imageFilter;url-patterns:="/image/*"
Web-SessionTimeout: 30
Web-WelcomeFiles: index.jsp, index.htm