如何检测当前的JSF版本?

Joc*_*hen 27 jsf version detection

我正在开发一个jsf-webapp,现在我需要知道我正在使用的JSF版本?我在哪里可以看到这个?提前致谢.

Bal*_*usC 44

以编程方式,你的意思是?你可以从中得到它Package#getImplementationVersion().

String version = FacesContext.class.getPackage().getImplementationVersion();
Run Code Online (Sandbox Code Playgroud)

还有顺便也getImplementationVendor()getImplementationTitle()方法.您可能也想使用它以区分供应商(例如,MyFaces或Mojarra).

或者你的意思是手动吗?只需查看/META-INF/MANIFEST.MFJSF impl JAR文件的文件即可.您可以使用ZIP工具提取JAR文件.它是Implementation-Version清单文件的条目.

  • 就像注意一样,似乎WebSphere(至少8.5.0.2)中包含的MyFaces实现没有为实现版本,供应商等设置值.您可能希望在上面补充代码以打印出实际装载的jar for FacesContext(和Facelet):`System.out.println("JSF API Location:"+ FacesContext.class.getProtectionDomain().getCodeSource());``System.out.println("JSF Impl Location:"+ Facelet ..class.getProtectionDomain()getCodeSource());` (5认同)
  • 仅供记录:最近的 [OmniFaces](http://showcase.omnifaces.org/) 版本在实用程序类 [`Faces`](http://showcase.omnifaces.org/utils/Faces) 中提供了方法 [ `getImplInfo()`](https://omnifaces.org/docs/javadoc/3.6/org/omnifaces/util/Faces.html#getImplInfo--),它返回的正是这个答案中描述的内容。这也可以在 EL 中通过“#{faces.implInfo}”获得。 (2认同)