osgi - Cannot retrieve BundleContext in a web application -
i have added following bundles can deploy war (web application) osgi framework.i use "apache felix distribuable binary" :
32|active | 20|ops4j pax logging - api (1.7.0) 33|active | 20|ops4j pax logging - service (1.7.1.snapshot) 34|active | 20|ops4j pax url - mvn: (1.3.5) 35|active | 20|ops4j pax url - war (1.3.5) 36|active | 20|ops4j pax url - wrap: (1.3.5) 37|active | 20|ops4j pax web - api (1.1.12) 38|active | 20|ops4j pax web - fileinstall deployer (1.1.12) 39|active | 20|ops4j pax web - extender - war (1.1.12) 40|active | 20|ops4j pax web - extender - whiteboard (1.1.12) 41|active | 20|ops4j pax web - jetty bundle (1.1.12) 42|active | 20|ops4j pax web - jsp support (1.1.12) 43|active | 20|ops4j pax web - runtime (1.1.12) 44|active | 20|ops4j pax web - service spi (1.1.12)
so, used simple struts 2 application (hello world) test, created war , put in "file install" directory, , became active, , can see welcome page.
after this, tried retrieve bundlecontext can use registered services war, have added:
bundlecontext ctx = (bundlecontext) servletactioncontext.getservletcontext().getattribute("osgi-bundlecontext");
but, found exception:
"java.lang.classcastexception: org.apache.felix.framework.bundlecontextimpl cannot cast org.osgi.framework.bundlecontext"
what can problem ?
thanks
making answer discussion in comments:
you have mentioned class twice in classpath. ones exists in osgi container , ones included in jar file. pax modules import class osgi container while webapp imports external jar file.
in case jar included in web-inf/lib. using maven should set scope of osgi-core dependency provided.
Comments
Post a Comment