我正在尝试将打包的ino WAB中的简单JSF应用程序部署到在Apache Felix OSGI容器中运行的Jetty实例。但是,我一直得到以下例外:
g! May 30, 2014 6:57:31 AM com.sun.faces.spi.InjectionProviderFactory createInstance
WARNING: JSF1033: Resource injection is DISABLED.
May 30, 2014 6:57:31 AM com.sun.faces.config.ConfigureListener contextInitialized
SEVERE: Critical error during deployment:
java.lang.NoClassDefFoundError: com/sun/faces/spi/InjectionProvider
at javax.faces.FactoryFinder$FactoryManager.copyInjectionProviderFromFacesContext(FactoryFinder.java:1051)
at javax.faces.FactoryFinder$FactoryManager.<init>(FactoryFinder.java:1035)
at javax.faces.FactoryFinder$FactoryManagerCache.getApplicationFactoryManager(FactoryFinder.java:856)
at javax.faces.FactoryFinder$FactoryManagerCache.getApplicationFactoryManager(FactoryFinder.java:793)
at javax.faces.FactoryFinder$FactoryManagerCache.access$100(FactoryFinder.java:768)
at javax.faces.FactoryFinder.setFactory(FactoryFinder.java:409)
at com.sun.faces.config.processor.FactoryConfigProcessor.setFactory(FactoryConfigProcessor.java:317)
at com.sun.faces.config.processor.FactoryConfigProcessor.processFactories(FactoryConfigProcessor.java:259)
at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:216)
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:435)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:214)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:446)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:792)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:296)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1359)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1352)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:744)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
at org.eclipse.jetty.osgi.boot.BundleWebAppProvider.bundleAdded(BundleWebAppProvider.java:154)
at org.eclipse.jetty.osgi.boot.internal.webapp.BundleWatcher.register(BundleWatcher.java:279)
at org.eclipse.jetty.osgi.boot.internal.webapp.BundleWatcher.addingBundle(BundleWatcher.java:189)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:467)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:414)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:443)
at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:869)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:790)
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:515)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4409)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2098)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1297)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.sun.faces.spi.InjectionProvider not found by javax.faces-api [21]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1550)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1988)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 40 more
这是OSGI容器中部署的捆绑包列表(最后一个是我的应用程序):
START LEVEL 1
ID|State |Level|Name
0|Active | 0|System Bundle (4.4.0)
1|Active | 1|CDI APIs (1.2.0)
2|Active | 1|Expression Language 3.0 (3.0.0)
3|Active | 1|Injection API (JSR 330) version 1 repackaged as OSGi bundle (2.2.0)
4|Active | 1|javax.interceptor API (1.2.0)
5|Active | 1|Java Servlet API (3.1.0)
6|Active | 1|JavaServer Pages(TM) API (2.3.1)
7|Active | 1|Java Server Pages Standard Tag Library API Bundle (1.2.0.v201105211821)
8|Active | 1|Jetty :: Deployers (9.2.0.M1)
9|Active | 1|Jetty :: Http Utility (9.2.0.M1)
10|Active | 1|Jetty :: IO Utility (9.2.0.M1)
11|Resolved | 1|Jetty JSP Fragment (2.3.3)
12|Active | 1|Jetty :: OSGi :: Boot (9.2.0.M1)
13|Resolved | 1|Jetty-OSGi-Jasper Integration (9.2.0.M1)
14|Active | 1|Jetty Servlet Schemas (3.1.0.M0)
15|Active | 1|Jetty :: Security (9.2.0.M1)
16|Active | 1|Jetty :: Server Core (9.2.0.M1)
17|Active | 1|Jetty :: Servlet Handling (9.2.0.M1)
18|Active | 1|Jetty :: Utilities (9.2.0.M1)
19|Active | 1|Jetty :: Webapp Application Support (9.2.0.M1)
20|Active | 1|Jetty :: XML utilities (9.2.0.M1)
21|Active | 1|JavaServer Faces API 2.2.6 (20140304-1538) (2.2.0)
22|Active | 1|Mojarra JSF Implementation 2.2.6 (20140304-1538) (2.2.6)
23|Active | 1|Apache Felix File Install (3.4.0)
24|Active | 1|Apache Felix Gogo Command (0.12.0)
25|Active | 1|Apache Felix Gogo Runtime (0.12.0)
26|Active | 1|Apache Felix Gogo Shell (0.10.0)
27|Active | 1|Java Server Pages Standard Tag Library Implementation Bundle provided by Glassfish (1.2.0.v201112081803)
28|Active | 1|Eclipse Compiler for Java(TM) (3.8.2.v20130121-145325)
29|Active | 1|osgi.cmpn (5.0.0.201305092017)
30|Active | 1|jsf-maven-osgi (0.9.0)
申请清单:
Manifest-Version: 1.0
Bundle-SymbolicName: jsf-maven-osgi
Archiver-Version: Plexus Archiver
Built-By: vlada
Bnd-LastModified: 1401425833034
Bundle-ManifestVersion: 2
Import-Package: javax.faces.context;version="[2.2,3)",com.sun.faces.sp
i;version="[2.2,3)",com.sun.faces.config;version="[2.2,3)",com.sun.fa
ces.vendor;version="[2.2,3)",javax.faces.webapp;version="[2.2,3)"
Tool: Bnd-2.1.0.20130426-122213
Export-Package: com.vektorsoft.demux.web.jsf;version="0.9.0"
Bundle-Name: jsf-maven-osgi
Bundle-Version: 0.9.0
Web-ContextPath: /hello
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_05
和web.xml:
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- <context-param>
<param-name>com.sun.faces.injectionProvider</param-name>
<param-value> com.sun.faces.vendor.WebContainerInjectionProvider</param-value>
</context-param>-->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
我认为这是某种OSGI类路径问题,因为它在非OSGI Jetty中部署时工作正常,但我无法弄清楚问题是什么。似乎我将所有必需的包导入WAB,但仍然没有。 希望有人能给我一个想法要找的东西。
答案 0 :(得分:2)
Mojarra 2.x存在问题。 jsf-api.jar中的类使用来自jsf-impl.jar的类,jsf-impl.jar中的许多类使用来自jsf-api.jar的类。我不知道他们怎么能够编译它们。
在此问题之后,您将遇到JSF API找不到许多工厂类的问题。为了解决这个问题,我简单地将jsf-impl包作为jsf-api的片段。为此,请将以下MANIFEST标头添加到jsf-impl:
中Fragment-Host: javax.faces-api
这样,jsf-api和jsf-impl将具有相同的类加载器,因此jsf-api将能够初始化所有Factory类。我们修补了这样的jsf-impl jar,并在OSGi中使用了JSF好几年。
好吧,最近我们决定不再使用JSF,因为它有许多错误(在构思和实现中)。
Mojarra实现在wab中查找web.xml,并在启动期间自行解析。这意味着如果JSF servlet只是使用whiteboard模式或通过HTTPService注册,它将无法工作。
<强>更新强>
我记得之前我曾写过一个Mojarra 2.2适配器。有关使JSF在OSGi容器中工作的技巧,请参阅自述文件:https://github.com/everit-org/osgi-mojarrajsf22adapter
答案 1 :(得分:0)
对于Eclipse和tomcat