JSF Web 应用程序作为 OSGi 包 - 出现错误 FacesContextFactory 未正确配置

JSF web app as OSGi bundle - getting error FacesContextFactory was not configured properly

我正在尝试将我的 JSF 应用程序转换为 OSGi Bundle (WAB),但是当我将 war 文件部署到 glassfish/autodeploy/bundles 时,我一直收到以下错误不太清楚这是什么意思。

[#|2016-09-06T11:35:05.402+0200|SEVERE|glassfish3.1.2|org.apache.catalina.core.ContainerBase|_ThreadID=61;_ThreadName=pool-5-thread-1;|ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: Factory 'javax.faces.context.FacesContextFactory' was not configured properly.
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:5389)
        at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
        at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
        at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
        at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
        at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
        at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
        at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
        at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.deploy(OSGiDeploymentRequest.java:183)
        at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.execute(OSGiDeploymentRequest.java:118)
        at org.glassfish.osgijavaeebase.AbstractOSGiDeployer.deploy(AbstractOSGiDeployer.java:121)
        at org.glassfish.osgijavaeebase.OSGiContainer.deploy(OSGiContainer.java:154)
        at org.glassfish.osgijavaeebase.JavaEEExtender.deploy(JavaEEExtender.java:107)
        at org.glassfish.osgijavaeebase.JavaEEExtender.access0(JavaEEExtender.java:61)
        at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer.call(JavaEEExtender.java:151)
        at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer.call(JavaEEExtender.java:148)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: Factory 'javax.faces.context.FacesContextFactory' was not configured properly.
        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:292)
        at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
        at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
        ... 24 more
Caused by: com.sun.faces.config.ConfigurationException: Factory 'javax.faces.context.FacesContextFactory' was not configured properly.
        at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:305)
        at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:219)
        at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:360)
        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:225)
        ... 27 more
Caused by: javax.faces.FacesException: com.sun.faces.context.InjectionFacesContextFactory
        at javax.faces.FactoryFinder.getImplGivenPreviousImpl(FactoryFinder.java:630)
        at javax.faces.FactoryFinder.getImplementationInstance(FactoryFinder.java:509)
        at javax.faces.FactoryFinder.access0(FactoryFinder.java:139)
        at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:993)
        at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:343)
        at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:303)
        ... 30 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at javax.faces.FactoryFinder.getImplGivenPreviousImpl(FactoryFinder.java:623)
        ... 35 more
|#]

我的war文件结构如下:

testWab.war
 |
 - img/
 - META-INF/
    |
    - MANIFEST.MF
 - WEB-INF/
    |
    - classes/
    |
    - lib/
       |
       - primefaces-5.3.jar
       |
       - javax.servlet.jsp-api-2.2.1.jar
       |
       - and other jar files 
    |
    - web.xml
    |
    - faces-config.xml
    |
    - web.xml
    |
    - glassfish-web.xml
 - views/
    |
    - all *.xhtml

我的 web.xml 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.FONT_AWESOME</param-name>
        <param-value>true</param-value>
    </context-param>

    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>

    <!-- Servlet Config -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

我的 glassfish-web.xml 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
    <context-root>/testWAB</context-root>
    <class-loader delegate="false"/>
    <property name="useBundledJsf" value="true"/>
</glassfish-web-app>

我的MANIFEST.MF是这样的:

Manifest-Verion: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: TestWAB
Bundle-Version: 0.1.0.SNAPSHOT
Bundle-Name: Simulation Vis
Import-Package: javax.servlet,
 javax.servlet.http,
 javax.ws.rs,
 javax.ws.rs.core,
 org.osgi.framework;version="1.3.0"
Bundle-ClassPath: WEB-INF/classes,
 WEB-INF/lib/commons-fileupload-1.3.jar,
 WEB-INF/lib/commons-io-2.2.jar,
 WEB-INF/lib/el-api-2.2.jar,
 WEB-INF/lib/el-impl-2.2.jar,
 WEB-INF/lib/javax.faces-api-2.2.jar,
 WEB-INF/lib/javax.servlet.jsp-api-2.2.1.jar,
 WEB-INF/lib/javax.servlet-api-3.1.0.jar,
 WEB-INF/lib/primefaces-5.3.jar
Web-ContextPath: /testWAB
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Activator: test.Activator
Require-Bundle: myBundle0;bundle-version="0.1.0";visibility:=reexport,
 myBundle1;bundle-version="0.1.0";visibility:=reexport,
 myBundle2;bundle-version="0.1.0"
Bundle-Vendor: FooBar

好的。因此,在费尽周折和键盘敲击之后,我终于让这些框架可以协同工作。

供您参考。


框架版本:

  • 玻璃鱼 3.1.2
  • Primefaces 5.3.0
  • OSGi 1.3.0

  1. Primefaces jar 不应在您的 WAR 的 WEB-INF/lib 文件夹中。它应该作为 OSGi Bundle 部署。这就像将 jar 放入 glassfish/autodeploy/bundles 目录一样简单。

  2. 将以下资源文件和目录从 Primefaces jar 的 META-INF 复制到您的网络包中:primefaces-p.taglib.xmlfaces-config.xmlresources

我的包已经有了自己的 faces-config.xml,所以我将 Primefaces primefaces-config.xml 中的一个重命名,并将其放在我的包 WEB-INF 下。然后我将以下内容添加到我的 web.xml 以使用这两个文件:

<context-param>
  <param-name>javax.faces.CONFIG_FILES</param-name>
  <param-value>
      /WEB-INF/faces-config.xml,
      /WEB-INF/primefaces-config.xml
  </param-value>
</context-param>
  1. 最后,我的WAB结构如下:

    testWab.war

    • img/
    • 资源/(来自 Primefaces jar)
    • META-INF/

      • MANIFEST.MF

      • primefaces-p.taglib.xml(来自 Primefaces jar)

    • WEB-INF/

      • 类/

      • lib/

        • 一些 jar 文件排除 primefaces jar
      • web.xml

      • 人脸-config.xml

      • primefaces-config.xml

      • web.xml

      • glassfish-web.xml

    • 浏览量/

      • 所有 *.xhtml

故障?

  1. 您的 Primefaces 版本可能不喜欢 Glassfish 附带的 jsf 版本。我建议您克制住包含自己的 jsf jar 的冲动,并告诉 Glassfish 到 useBundledJsf。我试过。浪费了无数个小时,没有任何效果。

理想情况下,您可以将框架升级到任何版本,以便它们可以很好地协同工作,但在我的情况下,不允许这样做,所以这就是我所做的。

我有 JSF 2.1 附带的 Glassfish 3.1.2,它不适用于 Primefaces 5.3。 我用 javax.faces-2.2.jar.

替换了原来的 glassfish\modules\javax.faces.jar

我的 glassfish-web.xml 看起来像这样:

<glassfish-web-app error-url="">
    <context-root>/testWAB</context-root>
    <class-loader delegate="true" />
</glassfish-web-app>
  1. 您的 WAB 突然找不到任何 Java 面孔 类。

确保包类路径正确并且 javax.faces.* 列在 Import-Package 下。

我的 MANIFEST.MF 看起来像这样:

Manifest-Verion: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: testWAB
Bundle-Version: 0.1.0.SNAPSHOT
Bundle-Name: Simulation Vis
Import-Package: javax.faces;version="2.2.0",
 javax.faces.application;version="2.2.0",
 javax.faces.bean,
 javax.faces.component;version="2.2.0",
 javax.faces.context;version="2.2.0",
 javax.faces.event;version="2.2.0",
 javax.servlet,
 javax.servlet.http,
 javax.ws.rs,
 javax.ws.rs.core,
 org.osgi.framework;version="1.3.0"
Bundle-ClassPath: WEB-INF/classes,
 WEB-INF/lib/jar1.jar,
 WEB-INF/lib/jar2.jar
Web-ContextPath: /testWAB
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Activator: test.Activator
Require-Bundle: myBundle1;bundle-version="0.1.0";visibility:=reexport,
 myBundle1;bundle-version="0.1.0";visibility:=reexport,
 org.primefaces;bundle-version="5.3.0"
Bundle-Vendor: Me