Hi,

David is right: you have interfaces/implementations present in two classloaders.

From a general point of view, you shouldn't put any jar into the karaf/lib folder.
If you install the war features:

features:install war

you will have the javax.servlet.* packages available (provided by Geronimo Spec bundle).
So you can use Import-Package: javax.servlet*

For non-OSGi jar, you can:
- find the OSGified version of the jar. ServiceMix provides a large set of wrap bundles: http://repo1.maven.org/maven2/org/apache/servicemix/bundles/ - you can use the wrap deployer which create an OSGi bundle on the fly using URL like wrap:mvn:.... or wrap:http:.... You can find more information about the wrap bundle here: http://karaf.apache.org/manual/2.1.99-SNAPSHOT/users-guide/deployer.html

Regards
JB

On 05/17/2011 07:48 AM, David Jencks wrote:
Your problem is that the servlet class is available from at least two bundles 
or classloaders and the implementation in your app is wired up to a different 
one from pax web.  There may be easier ways to see this but you can run 
investigate this in a debugger.

I'm pretty sure your problems are caused by putting the jars in karaf/lib and 
modifying the packages exported by the framework.  Instead, try to find or 
create bundleized versions of the jars and deploy them as bundles.  For 
instance, you won't need the servlet api jar since pax web already needs them 
installed...  Some ee spec jars need to be modified to work in osgi: both 
geronimo and servicemix have versions of these.

Others can probably give you more detailed advice on how to fix this...

david jencks

On May 16, 2011, at 9:36 PM, simplemind wrote:

I am new to this OSGi stuff and karaf, and I could really use some help
getting started.

I am trying to deploy a war bundle that uses resteasy servlet.  Here are
steps I took:

1. installed karaf 2.2.1 on linux ubuntu machine, latest java, latest
everything
2. built hello.war with MANIFEST.MF headers as described in Pax Web Extender
docs
3. added jsr311-api-1.1.1.jar, resteasy-jaxrs-2.1.0.GA.jar, and
servlet-api-2.5.jar to karaf/lib/ and karaf/deploy/
4. added org.osgi.framework.system.packages.extra= javax.ws.rs.core,
org.jboss.resteasy.plugins.server.servlet, javax.servlet.http, javax.servlet
in karaf/etc/config.properties
5. dropped hello.war into karaf/deploy/

3 and 4 was to get rid of NoClassDefFound errors on trying to start
hello.war when I did 5.  But then it got a class cast exception.  The
problem is that the class it is trying to cast from implements the interface
it is trying to cast to, so I can't understand why the cast is failing?

Here is proof of that:
http://docs.jboss.org/resteasy/docs/2.0.0.GA/javadocs/org/jboss/resteasy/plugins/server/servlet/HttpServletDispatcher.html

And here is the exception from the karaf log file:

java.lang.ClassCastException:
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher cannot be
cast to javax.servlet.Servlet
        at
org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC.visit(RegisterWebAppVisitorWC.java:200)[75:org.ops4j.pax.web.pax-web-extender-war:1.0.1]
        at
org.ops4j.pax.web.extender.war.internal.model.WebApp.accept(WebApp.java:583)[75:org.ops4j.pax.web.pax-web-extender-war:1.0.1]
        at
org.ops4j.pax.web.extender.war.internal.WebAppPublisher$HttpServiceListener.register(WebAppPublisher.java:170)[75:org.ops4j.pax.web.pax-web-extender-war:1.0.1]
...

--
View this message in context: 
http://karaf.922171.n3.nabble.com/strange-class-cast-exception-tp2951187p2951187.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to