Reputation: 188
I'm trying to deploy simple JSF application packaged ino WAB to Jetty instance running inside Apache Felix OSGI container. But, I keep getting the following exception:
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
This is the list of bundles deployed in OSGI container (the last one is my app):
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)
Application manifest:
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
And 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>
I suppose this is some kind of OSGI classpath issue, since it works fine when deployed in non-OSGI Jetty, but I can't figure out what the problem is. It seems I imported all required packages into WAB, but still nothing. Hope someone can give me an idea what to look for.
Upvotes: 0
Views: 4278
Reputation: 11469
For Eclipse and tomcat
Upvotes: 0
Reputation: 6046
There is an issue with Mojarra 2.x. A class in jsf-api.jar uses a class from jsf-impl.jar and many classes from jsf-impl.jar uses classes from jsf-api.jar. I do not know how they even be able to compile them.
After this issue you would have the problem that the JSF API would not find many factory classes. To solve that, I simply made the jsf-impl bundle to be the fragment of jsf-api. To do that, add the following MANIFEST header into jsf-impl:
Fragment-Host: javax.faces-api
With that, jsf-api and jsf-impl will have the same classloader so the jsf-api will be able to initialize all Factory classes. We patched the jsf-impl jar like this and used JSF within OSGi for several years.
Well, recently we decided not to use JSF anymore as it had many bugs (in conception and implementation).
The Mojarra implementation looks for the web.xml in the wab and parses that by itself during startup. That means that it will not be able to work if the JSF servlet was simply registered with whiteboard pattern or via HTTPService.
Update:
I just remembered that I wrote a Mojarra 2.2 adapter before. See the README for the tricks that made JSF work within an OSGi container: https://github.com/everit-org/osgi-mojarrajsf22adapter
Upvotes: 2