Developers creating applications for Liferay Portal CE 7.0 can choose to create them as Java EE-style Web Application ARchive (WAR) artifacts or as Java ARchive (JAR) OSGi bundle artifacts. Some portlet developers, however, don’t have that flexibility. Portlets like Spring MVC and JSF must be packaged as WAR artifacts because their frameworks are designed for Java EE. Therefore, they expect a WAR layout and require Java EE resources such as the
Liferay provides a way for these WAR-styled portlets to be deployed and treated like OSGi modules by Liferay’s OSGi runtime. They can be converted to *WAB*s.
Liferay Portal CE 7.0 supports the OSGi Web Application Bundle (WAB) standard for deployment of Java EE style WARs. Simply put, a WAB is an archive that has a WAR layout and contains a
META-INF/MANIFEST.MF file with the
Bundle-SymbolicName OSGi directive. Although the source of the project has a WAR layout, the artifact filename may end with either the
Liferay only supports the use of WABs if they’ve been auto-generated by the WAB Generator. The WAB Generator transforms a general WAR-style portlet into a WAB during its deployment process. So what exactly does the WAB Generator do to a WAR file to transform it into a WAB?
Consider the following folder structure of a WAR-style portlet:
- my-war-portlet - src - main - java - webapp - WEB-INF - resources - views - faces-config.xml - liferay-display.xml - liferay-plugin-package.properties - liferay-portlet.xml - portlet.xml - web.xml
When a WAR-style portlet is deployed to Liferay Portal and processed by the WAB Generator, the portlet’s folder structure is transformed to something like this
- my-war-portlet-that-is-now-a-wab - META-INF - MANIFEST.MF - WEB-INF - classes - lib - resources - views - faces-config.xml - liferay-display.xml - liferay-plugin-package.properties - liferay-portlet.xml - portlet.xml - web.xml
The major difference is the addition of the
META-INF/MANIFEST.MF file. The WAB Generator automatically generates an OSGi-ready
MANIFEST.MF file. If you want to affect the content of the manifest file, you can place BND directives and OSGi headers directly into the
WEB-INF/liferay-plugin-package.properties file. A
bnd.bnd and/or a build-time plugin (e.g.,
bnd-maven-plugin) should not be provided for your WAR plugin, because the generated WAB cannot make use of them.
Do you want to try this out for yourself? Follow the steps below to see the WAB Generator in action.
Create a WAR-style plugin that follows a similar structure to the one outlined above. You can download an example WAR-style portlet here, for demonstration.
Open your Liferay Portal instance in a file explorer and add a
portal-ext.propertiesfile with the following properties:
These properties store your generated WAB into your Liferay Portal instance’s
osgi/wabsfolder. You can learn more about these properties in the Module Framework Web Application Bundles properties section. Restart Liferay Portal for these changes to be recognized.
Copy your WAR plugin in your Liferay Portal instance’s
Navigate to your Liferay Portal instance’s
osgi/wabsfolder and inspect the generated WAB.
Awesome! You’ve seen the WAB Generator in action!