JSF web应用作为OSGi捆绑包-获取错误FacesContextFactory未正确配置

JSF web应用作为OSGi捆绑包-获取错误FacesContextFactory未正确配置,jsf,primefaces,glassfish,osgi,wab,Jsf,Primefaces,Glassfish,Osgi,Wab,我试图将我的JSF应用程序转换为OSGi捆绑包(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

我试图将我的JSF应用程序转换为OSGi捆绑包(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.access$200(JavaEEExtender.java:61)
        at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer$1.call(JavaEEExtender.java:151)
        at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer$1.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.access$400(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>
<?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-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
<glassfish-web-app error-url="">
    <context-root>/testWAB</context-root>
    <class-loader delegate="true" />
</glassfish-web-app>
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
我的
MANIFEST.MF
如下所示:

<?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>
<?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-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
<glassfish-web-app error-url="">
    <context-root>/testWAB</context-root>
    <class-loader delegate="true" />
</glassfish-web-app>
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

嗯。所以在做了大量的头发拉扯和键盘敲击之后,我终于让这些框架一起工作了

这是供你参考的


框架版本:

  • 玻璃鱼3.1.2
  • Primefaces 5.3.0
  • OSGi1.3.0

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

  • 将以下资源文件和目录从Primefaces jar的
    META-INF
    复制到您的web包中:
    Primefaces-p.taglib.xml
    faces config.xml
    resources

  • 我的bundle已经有了自己的
    faces config.xml
    ,所以我从Primefaces
    Primefaces config.xml
    重命名了它,并将它放在bundle的
    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>
    
  • 您的WAB突然找不到任何Java faces类
  • 确保bundle类路径正确,并且
    javax.faces.*
    列在
    Import Package

    我的
    MANIFEST.MF
    如下所示:

    <?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>
    
    <?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-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
    
    <glassfish-web-app error-url="">
        <context-root>/testWAB</context-root>
        <class-loader delegate="true" />
    </glassfish-web-app>
    
    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