32

I am developing a jsf-webapp and now I need to know what JSF-Version I am using? Where can I look this up? Thanks in advance.

Jochen
  • 1,746
  • 4
  • 22
  • 48

3 Answers3

54

Programmatically, you mean? You can get it from Package#getImplementationVersion().

String version = FacesContext.class.getPackage().getImplementationVersion();

There are by the way also getImplementationVendor() and getImplementationTitle() methods. You might want to use it as well in order to distinguish the vendor (MyFaces or Mojarra, for example).

Or do you mean manually? Just look in /META-INF/MANIFEST.MF file of the JSF impl JAR file. You can extract the JAR file with a ZIP tool. It's the Implementation-Version entry of the manifest file.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 5
    Just as a note, it appears that the MyFaces implementation included with WebSphere (8.5.0.2 at least) does not have values set for the implementation version, vendor, etc. You may wish to supplement above with code to print out the actual jar loaded for FacesContext (and Facelet): `System.out.println("JSF API Location: " + FacesContext.class.getProtectionDomain().getCodeSource());` `System.out.println("JSF Impl Location: " + Facelet.class.getProtectionDomain().getCodeSource());` – peater Apr 04 '14 at 14:13
  • Worked for me in JSF2.2, but returns null in JSF 2.3 – alfonx Jan 17 '18 at 15:31
  • 2
    Just for the records: recent [OmniFaces](http://showcase.omnifaces.org/) versions provide in the utility class [`Faces`](http://showcase.omnifaces.org/utils/Faces) the method [`getImplInfo()`](https://omnifaces.org/docs/javadoc/3.6/org/omnifaces/util/Faces.html#getImplInfo--), which returns exactly what is described in this answer. This is also available in EL via `#{faces.implInfo}`. – Martin Höller Jul 02 '20 at 07:09
  • And the primefaces version? Is there possible programmaticaly? – BicaBicudo Feb 13 '21 at 00:30
2

For me it wasn’t working with a WebSphere Server, so I followed the comment of peater:

System.out.println("JSF API Location: " + FacesContext.class.getProtectionDomain().getCodeSource());
System.out.println("JSF Impl Location: " + Facelet.class.getProtectionDomain().getCodeSource());

It showed me the version in the filename of the library:

JSF API Location: (file:/C:/workspaces/spielwiese/wlp/dev/api/spec/com.ibm.websphere.javaee.jsf.2.2_1.0.18.jar )

JSF Impl Location: (file:/C:/workspaces/spielwiese/wlp/dev/api/spec/com.ibm.websphere.javaee.jsf.2.2_1.0.18.jar )

Hannes Schneidermayer
  • 4,729
  • 2
  • 28
  • 32
  • Get only the version: FacesContext.class.getProtectionDomain().getCodeSource().toString().replaceAll("^.*faces-(\\d.*\\d).*$", "$1") – alfonx Jan 17 '18 at 15:35
-4

steps

1: unzip javax.faces.jar (extract to a folder),go to extract folder\META-INF

2: in side META-INF ,open MANIFEST.MF.

3: search for Implementation-Version

for example : Implementation-Version: 2.1.6-SNAPSHOT

sam
  • 5
  • 6