When you're doing maintenance on software, although it has been developed in-house, the first problem is to figure out which version is installed; this information is not always easy to retrieve, specially in a portal environment where there are a lot of installed plugins.
Fortunately Liferay offers 2 alternative ways to obtain the same information; but first let's try to figure out what the version number we're talking about is.
One of the file which describe a Liferay plugin is liferay-plugin-package.properties
; this file contains some informations including the module-incremental-version
property which represents our plugin build number.
When we prepare the WAR package to deploy, a file has been created with the Liferay version as a suffix followed by the build number: e.g. 6.2.0.5
.
If we want to know this number, after the plugin deploy, we can simply go to the Control Panel → App Manager menu and search for the plugin.
But what we really want is to retrieve this number using the Liferay API; in this way we could create a complex application and display the version number in every pages.
This is very simple:
<%
String context = ...;
PluginPackage pluginPackage = DeployManagerUtil.getInstalledPluginPackage(context);
%>
<%=pluginPackage.getVersion() %>
The PluginPackage
class contains some other useful informations, but now we're only interested in version number. Ok, but what context
is?
It's the servlet context name, namely the plugin's name (generally) as the Eclipse project's name. And how can we retrieve it?
If we're working inside the same plugin we can do:
- inside a JSP we can call
application.getServletContextName()
; - inside a Java class we can call
ClpSerializer.getServletContextName()
(if we have a service layer).
Or we can hardcode it.