4.2 Creating PARs and Web Applications
Prev | 4. Developing Applications | Next

## 4.2 Creating PARs and Web Applications

Virgo supports two OSGi-oriented ways of packaging applications: the PAR format and application bundles (including web bundles). The VTS also supports three distinct WAR deployment and packaging formats: standard Java EE WAR, Shared Libraries WAR, Shared Services WAR.

Virgo also supports plans as a way to describe an application. This method is similar to a PAR in that it encapsulates all the artifacts of an application as a single unit, but differs in that a plan simply lists the bundles in an XML file rather than packaging all the bundles in a single JAR file. The use of plans offers additional benefits to using PARs; for this reason, we recommend their use. For details, see Creating Plans.

### PARs

An OSGi application is packaged as a JAR file, with extension `.par`. A PAR artifact offers several benefits:

- A PAR file has an application name, version, symbolic name, and description.
- The artifacts of a PAR file are scoped so that they cannot be shared accidentally by other applications. The scope forms a boundary for automatic propagation of load time weaving and bundle refresh. See Plans and Scoping for more on scoping.
- Since a PAR is scoped, its artifacts have their exported packages imported by the synthetic context bundle which is used for thread context class loading. So, for example, hibernate will be able to load classes of any of the exported packages of the bundles in a PAR file using the thread context class loader.
- A PAR file is visible to management interfaces.
- A PAR file can be undeployed and redeployed as a unit.
- A PAR file is atomic in that it ties together the lifecycle of its artifacts. If you start, stop, or uninstall one of a PAR's artifacts, Virgo escalates the operation to the whole PAR file. So Virgo prevents artifacts of a PAR from being in inconsistent states. For example, if one artifact should fail to start, then Virgo stops all artifacts in the PAR.

See Plans and Scoping for more information on scoping.

A PAR includes one or more application bundles and its manifest specifies the following manifest headers:

Table 4.1. PAR file headers

Header | Description
--- | ---
`Application-SymbolicName` | Identifier for the application which, in combination with Application-Version, uniquely identifies an application
`Application-Name` | Human readable name of the application
`Application-Version` | Version of the application
`Application-Description` | Short description of the application

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

### Web Application Bundles

Virgo Server for Apache Tomcat supports Web Application Bundles that are compliant with the OSGi Web Applications specification. The defining property of a Bundle that makes it a Web Application Bundle is a manifest header, `Web-ContextPath`. This defines the context path the web application will be registered under.

See Using Spring and Spring DM for information on using Spring or Spring DM in a Web Application Bundle.

Prev | Up | Next
4. Developing Applications | Home | 4.3 Creating Plans