Access JSF and Primefaces version numbers programmatically

In PrimeFaces 4.0, Constants.VERSION is removed in favor of;

RequestContext.getCurrentInstance().getApplicationContext().getConfig().getBuildVersion();

Also watch out for FacesContext.class.getPackage().getImplementationVersion();, it doesn't work on some app servers like websphere.


For JSF:

//returns the major version (2.1)
FacesContext.class.getPackage().getImplementationVersion();

//returns the specification version (2.1)
Package.getPackage("com.sun.faces").getSpecificationVersion();

//returns the minor implementation version (2.1.x)
Package.getPackage("com.sun.faces").getImplementationVersion();

For Primefaces 3.x you can use the Constants class in utils package:

import org.primefaces.util.Constants;

Constants.VERSION

For PrimeFaces, you can use the Constants class:

org.primefaces.util.Constants.VERSION