You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Brad Cox <bc...@virtualschool.edu> on 2008/12/21 01:20:02 UTC
ClassCastException after ServiceTracker.getService()??
For the life of me I can't see why this fails. Here's the runup in detail:
coreTracker is a ServiceTracker for CoreServiceImpl, defined in a bundle
I'm trying to access from the integration test bundle. These are the
relevant declarations:
public interface CoreFactory extends ServiceFactory
public class CoreFactoryImpl implements CoreFactory
Integration test uses a ServiceTracker (CoreTracker) to locate the sole
core instance from the core bundle like this:
Object cso = coreTracker.getService();
System.out.println("cso:"+cso);
> cso:com.gestalt.soakit.core.internals.CoreFactoryImpl@dead19
So why should this cast fails with a ClassCastException?
CoreFactoryImpl cs = (CoreFactoryImpl)cso;
I'm going blind from staring at this. Maybe someone can spot what I'm
missing. Here's some more detail.
Class csoClass = cso.getClass();
System.out.println("csoClass:"+csoClass);
> csoClass:com.gestalt.soakit.core.internals.CoreFactoryImpl
Class[] csoClasses = csoClass.getClasses();
System.out.println("cso.getClasses():"+csoClass.getClasses());
> cso.getClasses():[Ljava.lang.Class;@1cc5ef
Class[] csoInterfaces = csoClass.getInterfaces();
System.out.println("cso.getInterfaces():"+csoClass.getInterfaces());
> cso.getInterfaces():[Ljava.lang.Class;@c44af4
Here's the full trace
> org.osgi.framework.BundleException: Activator start error in bundle
soakit.test [24].
> at org.apache.felix.framework.Felix._startBundle(Felix.java:1701)
> at org.apache.felix.framework.Felix.startBundle(Felix.java:1578)
> at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:382)
> at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:363)
> at
org.apache.felix.shell.impl.StartCommandImpl.execute(StartCommandImpl.java:82)
> at
org.apache.felix.shell.impl.Activator$ShellServiceImpl.executeCommand(Activator.java:276)
> at
org.apache.felix.shell.tui.Activator$ShellTuiRunnable.run(Activator.java:167)
> at java.lang.Thread.run(Thread.java:613)
> Caused by: java.lang.ClassCastException:
com.gestalt.soakit.core.internals.CoreFactoryImpl
> at
com.gestalt.soakit.test.internals.TestImpl.configure(TestImpl.java:49)
> at
com.gestalt.soakit.test.internals.TestFactoryImpl.createTest(TestFactoryImpl.java:35)
> at com.gestalt.soakit.test.TestActivator.start(TestActivator.java:54)
> at
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
> at org.apache.felix.framework.Felix._startBundle(Felix.java:1654)
> ... 7 more
> java.lang.ClassCastException:
com.gestalt.soakit.core.internals.CoreFactoryImpl
Re: ClassCastException after ServiceTracker.getService()??
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Brad Cox wrote:
> > One thing that seems weird to me, why are you casting to
> > CoreFactoryImpl instead of CoreFactory?
>
> Because I tried both;
> cso instanceof CoreFactory:false
> cso instanceof CoreFactoryImpl:false
>
> You nailed it:
> CoreFactoryImpl.class.getClassLoader():24.0
> cso.getClass().getClassLoader():16.0
I am not exactly sure what is going on here, but embedding dependencies
transitively with all imports being optional sounds like an accident
waiting to happen.
It is not surprising that you have two different bundles embedding the
same classes when you are embedding all dependencies. You need to take a
more measured approach to ensure proper sharing of classes. I understand
that this is difficult when you are starting with a big ball of someone
else's code, but there is really no way around it.
-> richard
>
> Looks like its time to return to the problem that's been bothering me
> from day one; the interaction of maven and eclipse around MANIFEST.MF,
> which I'm pretty sure is what's at the root of this.
>
> My goal is to describe everything in the pom and do all builds in
> maven, using eclipse solely for browsing and debugging. At some point
> I added this to every pom so that's what I'll be showing below:
> <manifestLocation>src/main/resources/META-INF</manifestLocation>
>
> I do maven builds like this: mvn -Dmaven.test.skip=true clean
> idea:clean eclipse:clean idea:idea eclipse:eclipse install. The test
> pom is at the end. The manifest maven-bundle-plugin generates follows
> with , replaced by ,\r\t for readability. Notice Import-Package drags
> in bizarre stuff (Swting?!!) and doesn't mention soakit.core, which
> should be providing most everything most bundles needs, with any
> strays picked up with <Embed-Transitive).
>
> Manifest-Version: 1.0
> Built-By: bradcox
> Bundle-Activator: com.gestalt.soakit.test.TestActivator
> Created-By: Apache Maven Bundle Plugin
> Import-Package: com.gestalt.soakit.test;resolution:=optional;version="
> 1.0",
> com.gestalt.soakit.test.internals;resolution:=optional;version="
> 1.0",
> com.sun.msv.datatype;resolution:=optional,
> com.sun.msv.datatype.x
> sd;resolution:=optional,
> com.sun.org.apache.xerces.internal.parsers;re
> solution:=optional,
> com.sun.org.apache.xerces.internal.util;resolution
> :=optional,
> com.sun.org.apache.xerces.internal.xni.parser;resolution:=
> optional,
> javax.swing;resolution:=optional,
> javax.swing.border;resoluti
> on:=optional,
> javax.swing.event;resolution:=optional,
> javax.swing.table
> ;resolution:=optional,
> javax.swing.text;resolution:=optional,
> javax.swi
> ng.tree;resolution:=optional,
> javax.xml.datatype;resolution:=optional,
>
> javax.xml.stream;resolution:=optional,
> javax.xml.stream.events;resolut
> ion:=optional,
> javax.xml.stream.util;resolution:=optional,
> org.apache.x
> ml.resolver;resolution:=optional,
> org.apache.xml.resolver.readers;reso
> lution:=optional,
> org.gjt.xpp;resolution:=optional,
> org.jdom;resolution
> :=optional,
> org.jdom.input;resolution:=optional,
> org.osgi.framework;res
> olution:=optional,
> org.osgi.util.tracker;resolution:=optional,
> org.rela
> xng.datatype;resolution:=optional,
> org.xmlpull.v1;resolution:=optional
> ,
> sun.io;resolution:=optional
> Bundle-RequiredExecutionEnvironment: J2SE-1.5
> Embed-Transitive: true
> Bnd-LastModified: 1229859848087
> Export-Package: com.gestalt.soakit.test;uses:="com.gestalt.soakit.test
> .internals,
> org.osgi.framework";version="1.0.0.SNAPSHOT",
> com.gestalt.s
> oakit.test.internals;uses:="org.osgi.framework,
> com.gestalt.soakit.tes
> t";version="1.0.0.SNAPSHOT"
> Bundle-Version: 1.0.0.SNAPSHOT
> Bundle-Name: soakit.test
> Bundle-Description: Integration tests for soakit core and components
> Bundle-ClassPath: .,
> xalan-2.6.0.jar,
> icu4j-3.8.jar,
> jaxme-api-0.3.jar,
> xm
> lParserAPIs-2.6.2.jar,
> xercesImpl-2.6.2.jar,
> junit-4.4.jar,
> jaxen-1.1-be
> ta-4.jar,
> dom4j-1.5.2.jar,
> xml-apis-1.0.b2.jar,
> xom-1.1d2.jar,
> soakit.cor
> e-1.0-SNAPSHOT.jar
> Build-Jdk: 1.5.0_16
> Private-Package: nu.xom,
> org.apache.xalan.xsltc.compiler,
> com.ibm.icu.im
> pl.data.icudt38b,
> javax.xml.namespace,
> com.ibm.icu.impl.data.icudt38b.r
> bnf,
> org.w3c.dom.events,
> org.apache.xerces.impl.xs.traversers,
> org.dom4j
> .persistence.nativ,
> org.jaxen.saxpath,
> org.apache.xerces.util,
> org.apach
> e.xpath.patterns,
> com.ibm.icu.math,
> com.ibm.icu.text,
> junit.runner,
> org.a
> pache.xpath.res,
> com.ibm.icu.impl.data.icudt38b.translit,
> javax.xml.par
> sers,
> org.apache.xerces.jaxp,
> nu.xom.xinclude,
> org.apache.xml.dtm,
> org.ap
> ache.bcel.verifier.structurals,
> javax.xml.transform.stream,
> org.dom4j.p
> ersistence,
> org.dom4j.dom,
> org.apache.xalan.xsltc.compiler.util,
> org.jun
> it.internal,
> org.apache.xalan.xsltc.runtime,
> org.apache.html.dom,
> org.do
> m4j.io,
> org.apache.xalan.xslt,
> org.dom4j.swing,
> org.apache.xerces.impl.x
> s.util,
> org.w3c.dom.stylesheets,
> org.apache.xerces.impl,
> com.ibm.icu.imp
> l,
> org.apache.xpath.axes,
> org.junit.experimental.theories.suppliers,
> org
> .apache.xerces.xs,
> javax.xml.bind.util,
> org.junit.experimental.theories
> ,
> com.ibm.icu.impl.duration.impl.data,
> org.apache.xml.utils,
> com.ibm.icu
> .lang,
> org.apache.xalan.serialize,
> org.apache.xerces.impl.xs.models,
> org
> .apache.xalan.res,
> org.xml.sax.ext,
> org.xml.sax.helpers,
> org.apache.xerc
> es.xni.grammars,
> org.apache.xerces.impl.xs,
> org.apache.xpath.operations
> ,
> javax.xml.bind,
> org.dom4j.rule,
> org.apache.xalan.extensions,
> org.dom4j.
> rule.pattern,
> org.w3c.dom.ls,
> org.apache.bcel,
> org.junit.experimental.th
> eories.internal,
> org.apache.xerces.parsers,
> org.apache.xalan.xsltc.cmdl
> ine.getopt,
> org.apache.xml.utils.res,
> org.apache.xerces.xni.parser,
> org.
> apache.xalan.xsltc.trax,
> org.apache.bcel.generic,
> org.apache.xerces.imp
> l.dv.xs,
> com.ibm.icu.impl.data,
> nu.xom.xslt,
> org.apache.xml.res,
> org.jaxe
> n.function.xslt,
> org.apache.xerces.impl.xpath.regex,
> org.jaxen.dom.html
> ,
> org.apache.xalan.templates,
> org.apache.xalan.xsltc,
> org.hamcrest.core,
>
> org.hamcrest,
> com.ibm.icu.impl.data.icudt38b.coll,
> org.apache.xerces.im
> pl.dv.util,
> org.w3c.dom.views,
> org.dom4j.xpp,
> org.apache.xerces.impl.xs.
> opti,
> junit.extensions,
> org.apache.xerces.impl.io,
> org.apache.xerces.imp
> l.dv.dtd,
> junit.textui,
> org.apache.xpath.compiler,
> com.ibm.icu.impl.data
> .icudt38b.brkitr,
> org.apache.wml.dom,
> org.apache.bcel.util,
> org.apache.x
> erces.impl.xs.identity,
> javax.xml.transform.dom,
> org.w3c.dom.traversal,
>
> org.dom4j,
> org.apache.xerces.dom3,
> org.jaxen.javabean,
> javax.xml.bind.he
> lpers,
> org.apache.xmlcommons,
> org.jaxen.util,
> org.dom4j.jaxb,
> org.junit.m
> atchers,
> org.apache.wml,
> com.gestalt.soakit.core.internals,
> org.apache.b
> cel.verifier.exc,
> com.gestalt.soakit.core,
> org.jaxen.function,
> com.ibm.i
> cu.impl.duration,
> org.junit.runners,
> org.apache.xpath.functions,
> org.apa
> che.xml.dtm.ref,
> org.apache.xalan.xsltc.util,
> org.apache.xalan.transfor
> mer,
> org.junit.experimental.results,
> org.apache.bcel.classfile,
> org.apac
> he.xerces.dom3.bootstrap,
> org.junit.runner.notification,
> javax.xml.tran
> sform,
> org.apache.xerces.impl.dtd,
> org.dom4j.xpath,
> org.junit.internal.r
> equests,
> org.w3c.dom.css,
> org.jaxen.dom4j,
> org.apache.xerces.impl.dv,
> org
> .apache.xerces.dom3.as,
> org.apache.xalan.processor,
> org.apache.xpath,
> or
> g.dom4j.dtd,
> com.ibm.icu.util,
> org.apache.xerces.xni,
> org.junit.runner,
> o
> rg.dom4j.datatype,
> nu.xom.converters,
> org.apache.xalan,
> nu.xom.canonical
> ,
> org.apache.xerces.dom.events,
> org.w3c.dom.html,
> org.apache.xalan.xsltc
> .runtime.output,
> org.jaxen.expr,
> org.apache.xerces.xinclude,
> lib,
> org.apa
> che.xerces.impl.xpath,
> org.junit.runner.manipulation,
> org.apache.xalan.
> xsltc.dom,
> org.apache.regexp,
> org.apache.xalan.client,
> org.jaxen.pattern
> ,
> license,
> org.apache.xalan.xsltc.cmdline,
> org.apache.xml.dtm.ref.dom2dt
> m,
> org.w3c.dom.ranges,
> org.dom4j.bean,
> org.jaxen.jdom,
> org.apache.xpath.d
> omapi,
> org.apache.xerces.impl.validation,
> org.apache.bcel.verifier,
> org.
> jaxen.function.ext,
> org.jaxen.saxpath.base,
> org.apache.xerces.impl.dtd.
> models,
> org.dom4j.tree,
> org.jaxen.dom,
> org.dom4j.util,
> org.junit.internal
> .runners,
> org.jaxen,
> java_cup.runtime,
> org.apache.xpath.objects,
> org.apac
> he.bcel.verifier.statics,
> org.apache.xalan.lib,
> org.jaxen.expr.iter,
> org
> .apache.xerces.impl.msg,
> org.apache.xalan.trace,
> org.apache.xml.seriali
> zer,
> nu.xom.tests,
> org.xml.sax,
> org.apache.xerces.dom,
> org.hamcrest.inter
> nal,
> org.apache.xml.dtm.ref.sax2dtm,
> org.junit,
> org.apache.xalan.lib.sql
> ,
> org.apache.xml.serialize,
> org.w3c.dom,
> javax.xml,
> com.ibm.icu.impl.dura
> tion.impl,
> org.jaxen.xom,
> javax.xml.transform.sax,
> org.jaxen.saxpath.hel
> pers,
> org.w3c.dom.xpath,
> junit.framework
> Originally-Created-By: Apache Maven Bundle Plugin
> Bundle-ManifestVersion: 2
> Bundle-SymbolicName: soakit.test
> Tool: Bnd-0.0.295
> Embed-Dependency: *;scope=compile|runtime;inline=false
>
> If I now launch eclipse and open that same file in the dependencies
> GUI pane, I see the bizarre packages and no soakit.core. I delete the
> strays, add soakit.core, clear out the strays on Runtime/Classpath,
> and use Overview/Organize Manifests Wizard, and wind up with something
> that looks pretty reasonable:
>
> Manifest-Version: 1.0
> Built-By: bradcox
> Bundle-Activator: com.gestalt.soakit.test.TestActivator
> Created-By: Apache Maven Bundle Plugin
> Import-Package: com.gestalt.soakit.core;version="1.0.0.SNAPSHOT",
> com.gestalt.soakit.core.internals;version="1.0.0.SNAPSHOT",
> com.gestalt.soakit.test;version="1.0";resolution:=optional,
> com.gestalt.soakit.test.internals;version="1.0";resolution:=optional
> Bundle-RequiredExecutionEnvironment: J2SE-1.5
> Embed-Transitive: true
> Bnd-LastModified: 1229859848087
> Export-Package: com.gestalt.soakit.test;uses:="com.gestalt.soakit.test
> .internals,
> org.osgi.framework";version="1.0.0.SNAPSHOT",
> com.gestalt.s
> oakit.test.internals;uses:="org.osgi.framework,
> com.gestalt.soakit.tes
> t";version="1.0.0.SNAPSHOT"
> Bundle-Version: 1.0.0.SNAPSHOT
> Bundle-Name: soakit.test
> Bundle-Description: Integration tests for soakit core and components
> Bundle-ClassPath: .
> Build-Jdk: 1.5.0_16
> Private-Package: nu.xom,
> org.apache.xalan.xsltc.compiler,
> com.ibm.icu.im
> pl.data.icudt38b,
> javax.xml.namespace,
> com.ibm.icu.impl.data.icudt38b.r
> bnf,
> org.w3c.dom.events,
> org.apache.xerces.impl.xs.traversers,
> org.dom4j
> .persistence.nativ,
> org.jaxen.saxpath,
> org.apache.xerces.util,
> org.apach
> e.xpath.patterns,
> com.ibm.icu.math,
> com.ibm.icu.text,
> junit.runner,
> org.a
> pache.xpath.res,
> com.ibm.icu.impl.data.icudt38b.translit,
> javax.xml.par
> sers,
> org.apache.xerces.jaxp,
> nu.xom.xinclude,
> org.apache.xml.dtm,
> org.ap
> ache.bcel.verifier.structurals,
> javax.xml.transform.stream,
> org.dom4j.p
> ersistence,
> org.dom4j.dom,
> org.apache.xalan.xsltc.compiler.util,
> org.jun
> it.internal,
> org.apache.xalan.xsltc.runtime,
> org.apache.html.dom,
> org.do
> m4j.io,
> org.apache.xalan.xslt,
> org.dom4j.swing,
> org.apache.xerces.impl.x
> s.util,
> org.w3c.dom.stylesheets,
> org.apache.xerces.impl,
> com.ibm.icu.imp
> l,
> org.apache.xpath.axes,
> org.junit.experimental.theories.suppliers,
> org
> .apache.xerces.xs,
> javax.xml.bind.util,
> org.junit.experimental.theories
> ,
> com.ibm.icu.impl.duration.impl.data,
> org.apache.xml.utils,
> com.ibm.icu
> .lang,
> org.apache.xalan.serialize,
> org.apache.xerces.impl.xs.models,
> org
> .apache.xalan.res,
> org.xml.sax.ext,
> org.xml.sax.helpers,
> org.apache.xerc
> es.xni.grammars,
> org.apache.xerces.impl.xs,
> org.apache.xpath.operations
> ,
> javax.xml.bind,
> org.dom4j.rule,
> org.apache.xalan.extensions,
> org.dom4j.
> rule.pattern,
> org.w3c.dom.ls,
> org.apache.bcel,
> org.junit.experimental.th
> eories.internal,
> org.apache.xerces.parsers,
> org.apache.xalan.xsltc.cmdl
> ine.getopt,
> org.apache.xml.utils.res,
> org.apache.xerces.xni.parser,
> org.
> apache.xalan.xsltc.trax,
> org.apache.bcel.generic,
> org.apache.xerces.imp
> l.dv.xs,
> com.ibm.icu.impl.data,
> nu.xom.xslt,
> org.apache.xml.res,
> org.jaxe
> n.function.xslt,
> org.apache.xerces.impl.xpath.regex,
> org.jaxen.dom.html
> ,
> org.apache.xalan.templates,
> org.apache.xalan.xsltc,
> org.hamcrest.core,
>
> org.hamcrest,
> com.ibm.icu.impl.data.icudt38b.coll,
> org.apache.xerces.im
> pl.dv.util,
> org.w3c.dom.views,
> org.dom4j.xpp,
> org.apache.xerces.impl.xs.
> opti,
> junit.extensions,
> org.apache.xerces.impl.io,
> org.apache.xerces.imp
> l.dv.dtd,
> junit.textui,
> org.apache.xpath.compiler,
> com.ibm.icu.impl.data
> .icudt38b.brkitr,
> org.apache.wml.dom,
> org.apache.bcel.util,
> org.apache.x
> erces.impl.xs.identity,
> javax.xml.transform.dom,
> org.w3c.dom.traversal,
>
> org.dom4j,
> org.apache.xerces.dom3,
> org.jaxen.javabean,
> javax.xml.bind.he
> lpers,
> org.apache.xmlcommons,
> org.jaxen.util,
> org.dom4j.jaxb,
> org.junit.m
> atchers,
> org.apache.wml,
> com.gestalt.soakit.core.internals,
> org.apache.b
> cel.verifier.exc,
> com.gestalt.soakit.core,
> org.jaxen.function,
> com.ibm.i
> cu.impl.duration,
> org.junit.runners,
> org.apache.xpath.functions,
> org.apa
> che.xml.dtm.ref,
> org.apache.xalan.xsltc.util,
> org.apache.xalan.transfor
> mer,
> org.junit.experimental.results,
> org.apache.bcel.classfile,
> org.apac
> he.xerces.dom3.bootstrap,
> org.junit.runner.notification,
> javax.xml.tran
> sform,
> org.apache.xerces.impl.dtd,
> org.dom4j.xpath,
> org.junit.internal.r
> equests,
> org.w3c.dom.css,
> org.jaxen.dom4j,
> org.apache.xerces.impl.dv,
> org
> .apache.xerces.dom3.as,
> org.apache.xalan.processor,
> org.apache.xpath,
> or
> g.dom4j.dtd,
> com.ibm.icu.util,
> org.apache.xerces.xni,
> org.junit.runner,
> o
> rg.dom4j.datatype,
> nu.xom.converters,
> org.apache.xalan,
> nu.xom.canonical
> ,
> org.apache.xerces.dom.events,
> org.w3c.dom.html,
> org.apache.xalan.xsltc
> .runtime.output,
> org.jaxen.expr,
> org.apache.xerces.xinclude,
> lib,
> org.apa
> che.xerces.impl.xpath,
> org.junit.runner.manipulation,
> org.apache.xalan.
> xsltc.dom,
> org.apache.regexp,
> org.apache.xalan.client,
> org.jaxen.pattern
> ,
> license,
> org.apache.xalan.xsltc.cmdline,
> org.apache.xml.dtm.ref.dom2dt
> m,
> org.w3c.dom.ranges,
> org.dom4j.bean,
> org.jaxen.jdom,
> org.apache.xpath.d
> omapi,
> org.apache.xerces.impl.validation,
> org.apache.bcel.verifier,
> org.
> jaxen.function.ext,
> org.jaxen.saxpath.base,
> org.apache.xerces.impl.dtd.
> models,
> org.dom4j.tree,
> org.jaxen.dom,
> org.dom4j.util,
> org.junit.internal
> .runners,
> org.jaxen,
> java_cup.runtime,
> org.apache.xpath.objects,
> org.apac
> he.bcel.verifier.statics,
> org.apache.xalan.lib,
> org.jaxen.expr.iter,
> org
> .apache.xerces.impl.msg,
> org.apache.xalan.trace,
> org.apache.xml.seriali
> zer,
> nu.xom.tests,
> org.xml.sax,
> org.apache.xerces.dom,
> org.hamcrest.inter
> nal,
> org.apache.xml.dtm.ref.sax2dtm,
> org.junit,
> org.apache.xalan.lib.sql
> ,
> org.apache.xml.serialize,
> org.w3c.dom,
> javax.xml,
> com.ibm.icu.impl.dura
> tion.impl,
> org.jaxen.xom,
> javax.xml.transform.sax,
> org.jaxen.saxpath.hel
> pers,
> org.w3c.dom.xpath,
> junit.framework
> Originally-Created-By: Apache Maven Bundle Plugin
> Bundle-ManifestVersion: 2
> Bundle-SymbolicName: soakit.test
> Tool: Bnd-0.0.295
> Embed-Dependency: *;scope=compile|runtime;inline=false
>
> But as soon as I do a full build to get something executable (I've
> given up on getting eclipse to build anything executable until
> somebody provides the secret sauce), maven overwrites this with the
> invalid version.
>
> I think what's going on is that maven's manifest prevails so test is
> getting soakit.core from two places. Based on that, I'll try reworking
> the pom to remove any ambiguity. Could really use any suggestions on
> that.
>
> But even more, I could really use a better understanding of why maven
> and eclipse aren't working together now, and a fool proof recipe for
> how to make them coexist going forward.
>
> I've also tried Netbeans and IntelliJ but these all fail for various
> reasons (bnd runs out of memory in IntelliJ building soakit.core for
> one). Using Pax-Runner fails running some Eclipse ant script trying to
> read bizarre directories. Every environ fails with a different problem.
>
> The only common factor is my busted mental model of how maven and
> eclipse work together. Can someone set me straight? Here's my (no
> doubt) busted pom:
>
> <?xml version="1.0" encoding="utf-8"?>
> <project
> xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd"
> >
> <modelVersion>4.0.0</modelVersion>
> <groupId>soakit</groupId>
> <artifactId>soakit.test</artifactId>
> <version>1.0-SNAPSHOT</version>
> <name>soakit.test</name>
> <description>Integration tests for soakit core and
> components</description>
> <packaging>bundle</packaging>
>
> <parent>
> <groupId>soakit</groupId>
> <artifactId>soakit</artifactId>
> <version>1.0-SNAPSHOT</version>
> </parent>
>
> <dependencies>
> <dependency>
> <groupId>soakit</groupId>
> <artifactId>soakit.core</artifactId>
> <version>1.0-SNAPSHOT</version>
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.4</version>
> </dependency>
> <!--
> <dependency>
> <groupId>javax.servlet</groupId>
> <artifactId>servlet-api</artifactId>
> <version>2.5</version>
> </dependency>
> <dependency>
> <groupId>org.apache.felix</groupId>
> <artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
> <version>1.1.0-SNAPSHOT</version>
> </dependency>
> -->
> </dependencies>
>
> <build>
> <plugins>
> <plugin>
> <groupId>org.apache.felix</groupId>
> <artifactId>maven-bundle-plugin</artifactId>
> <version>1.5.0-SNAPSHOT</version>
> <extensions>true</extensions>
> <configuration>
>
> <manifestLocation>src/main/resources/META-INF</manifestLocation>
> <instructions>
> <Bundle-Version>${pom.version}</Bundle-Version>
>
> <Bundle-SymbolicName>soakit.test</Bundle-SymbolicName>
> <Bundle-RequiredExecutionEnvironment>
> J2SE-1.5
> </Bundle-RequiredExecutionEnvironment>
> <Bundle-Activator>
> com.gestalt.soakit.test.TestActivator
> </Bundle-Activator>
> <Export-Package>
>
> com.gestalt.soakit.test.*;version="${pom.version}",
> </Export-Package>
> <Import-Package>
> *;resolution:=optional
> </Import-Package>
>
> <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
> <Embed-Transitive>true</Embed-Transitive>
> </instructions>
> </configuration>
> <executions>
> <execution>
> <id>manifest</id>
> <goals>
> <goal>manifest</goal>
> </goals>
> <phase>process-resources</phase>
> </execution>
> </executions>
> </plugin>
> </plugins>
> </build>
> </project>
>
>
>
>
>
> Richard S. Hall wrote:
>> Try printing CoreFactoryImpl.class.getClassLoader() within your
>> bundle using the service tracker and then print
>> cso.getClass().getClassLoader() from the service object and see if
>> they are coming from the same class loader.
>>
>> One thing that seems weird to me, why are you casting to
>> CoreFactoryImpl instead of CoreFactory?
>>
>> -> richard
>>
>> Brad Cox wrote:
>>> For the life of me I can't see why this fails. Here's the runup in
>>> detail:
>>>
>>> coreTracker is a ServiceTracker for CoreServiceImpl, defined in a
>>> bundle I'm trying to access from the integration test bundle. These
>>> are the relevant declarations:
>>>
>>> public interface CoreFactory extends ServiceFactory
>>> public class CoreFactoryImpl implements CoreFactory
>>>
>>> Integration test uses a ServiceTracker (CoreTracker) to locate the
>>> sole core instance from the core bundle like this:
>>>
>>> Object cso = coreTracker.getService();
>>> System.out.println("cso:"+cso);
>>> > cso:com.gestalt.soakit.core.internals.CoreFactoryImpl@dead19
>>>
>>> So why should this cast fails with a ClassCastException?
>>> CoreFactoryImpl cs = (CoreFactoryImpl)cso;
>>>
>>> I'm going blind from staring at this. Maybe someone can spot what
>>> I'm missing. Here's some more detail.
>>>
>>> Class csoClass = cso.getClass();
>>> System.out.println("csoClass:"+csoClass);
>>> > csoClass:com.gestalt.soakit.core.internals.CoreFactoryImpl
>>>
>>> Class[] csoClasses = csoClass.getClasses();
>>> System.out.println("cso.getClasses():"+csoClass.getClasses());
>>> > cso.getClasses():[Ljava.lang.Class;@1cc5ef
>>>
>>> Class[] csoInterfaces = csoClass.getInterfaces();
>>> System.out.println("cso.getInterfaces():"+csoClass.getInterfaces());
>>> > cso.getInterfaces():[Ljava.lang.Class;@c44af4
>>>
>>> Here's the full trace
>>>
>>> > org.osgi.framework.BundleException: Activator start error in
>>> bundle soakit.test [24].
>>> > at org.apache.felix.framework.Felix._startBundle(Felix.java:1701)
>>> > at org.apache.felix.framework.Felix.startBundle(Felix.java:1578)
>>> > at
>>> org.apache.felix.framework.BundleImpl.start(BundleImpl.java:382)
>>> > at
>>> org.apache.felix.framework.BundleImpl.start(BundleImpl.java:363)
>>> > at
>>> org.apache.felix.shell.impl.StartCommandImpl.execute(StartCommandImpl.java:82)
>>>
>>> > at
>>> org.apache.felix.shell.impl.Activator$ShellServiceImpl.executeCommand(Activator.java:276)
>>>
>>> > at
>>> org.apache.felix.shell.tui.Activator$ShellTuiRunnable.run(Activator.java:167)
>>>
>>> > at java.lang.Thread.run(Thread.java:613)
>>> > Caused by: java.lang.ClassCastException:
>>> com.gestalt.soakit.core.internals.CoreFactoryImpl
>>> > at
>>> com.gestalt.soakit.test.internals.TestImpl.configure(TestImpl.java:49)
>>> > at
>>> com.gestalt.soakit.test.internals.TestFactoryImpl.createTest(TestFactoryImpl.java:35)
>>>
>>> > at
>>> com.gestalt.soakit.test.TestActivator.start(TestActivator.java:54)
>>> > at
>>> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
>>>
>>> > at org.apache.felix.framework.Felix._startBundle(Felix.java:1654)
>>> > ... 7 more
>>> > java.lang.ClassCastException:
>>> com.gestalt.soakit.core.internals.CoreFactoryImpl
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: ClassCastException after ServiceTracker.getService()??
Posted by Brad Cox <bc...@virtualschool.edu>.
> One thing that seems weird to me, why are you casting to
> CoreFactoryImpl instead of CoreFactory?
Because I tried both;
cso instanceof CoreFactory:false
cso instanceof CoreFactoryImpl:false
You nailed it:
CoreFactoryImpl.class.getClassLoader():24.0
cso.getClass().getClassLoader():16.0
Looks like its time to return to the problem that's been bothering me
from day one; the interaction of maven and eclipse around MANIFEST.MF,
which I'm pretty sure is what's at the root of this.
My goal is to describe everything in the pom and do all builds in maven,
using eclipse solely for browsing and debugging. At some point I added
this to every pom so that's what I'll be showing below:
<manifestLocation>src/main/resources/META-INF</manifestLocation>
I do maven builds like this: mvn -Dmaven.test.skip=true clean idea:clean
eclipse:clean idea:idea eclipse:eclipse install. The test pom is at the
end. The manifest maven-bundle-plugin generates follows with , replaced
by ,\r\t for readability. Notice Import-Package drags in bizarre stuff
(Swting?!!) and doesn't mention soakit.core, which should be providing
most everything most bundles needs, with any strays picked up with
<Embed-Transitive).
Manifest-Version: 1.0
Built-By: bradcox
Bundle-Activator: com.gestalt.soakit.test.TestActivator
Created-By: Apache Maven Bundle Plugin
Import-Package: com.gestalt.soakit.test;resolution:=optional;version="
1.0",
com.gestalt.soakit.test.internals;resolution:=optional;version="
1.0",
com.sun.msv.datatype;resolution:=optional,
com.sun.msv.datatype.x
sd;resolution:=optional,
com.sun.org.apache.xerces.internal.parsers;re
solution:=optional,
com.sun.org.apache.xerces.internal.util;resolution
:=optional,
com.sun.org.apache.xerces.internal.xni.parser;resolution:=
optional,
javax.swing;resolution:=optional,
javax.swing.border;resoluti
on:=optional,
javax.swing.event;resolution:=optional,
javax.swing.table
;resolution:=optional,
javax.swing.text;resolution:=optional,
javax.swi
ng.tree;resolution:=optional,
javax.xml.datatype;resolution:=optional,
javax.xml.stream;resolution:=optional,
javax.xml.stream.events;resolut
ion:=optional,
javax.xml.stream.util;resolution:=optional,
org.apache.x
ml.resolver;resolution:=optional,
org.apache.xml.resolver.readers;reso
lution:=optional,
org.gjt.xpp;resolution:=optional,
org.jdom;resolution
:=optional,
org.jdom.input;resolution:=optional,
org.osgi.framework;res
olution:=optional,
org.osgi.util.tracker;resolution:=optional,
org.rela
xng.datatype;resolution:=optional,
org.xmlpull.v1;resolution:=optional
,
sun.io;resolution:=optional
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Embed-Transitive: true
Bnd-LastModified: 1229859848087
Export-Package: com.gestalt.soakit.test;uses:="com.gestalt.soakit.test
.internals,
org.osgi.framework";version="1.0.0.SNAPSHOT",
com.gestalt.s
oakit.test.internals;uses:="org.osgi.framework,
com.gestalt.soakit.tes
t";version="1.0.0.SNAPSHOT"
Bundle-Version: 1.0.0.SNAPSHOT
Bundle-Name: soakit.test
Bundle-Description: Integration tests for soakit core and components
Bundle-ClassPath: .,
xalan-2.6.0.jar,
icu4j-3.8.jar,
jaxme-api-0.3.jar,
xm
lParserAPIs-2.6.2.jar,
xercesImpl-2.6.2.jar,
junit-4.4.jar,
jaxen-1.1-be
ta-4.jar,
dom4j-1.5.2.jar,
xml-apis-1.0.b2.jar,
xom-1.1d2.jar,
soakit.cor
e-1.0-SNAPSHOT.jar
Build-Jdk: 1.5.0_16
Private-Package: nu.xom,
org.apache.xalan.xsltc.compiler,
com.ibm.icu.im
pl.data.icudt38b,
javax.xml.namespace,
com.ibm.icu.impl.data.icudt38b.r
bnf,
org.w3c.dom.events,
org.apache.xerces.impl.xs.traversers,
org.dom4j
.persistence.nativ,
org.jaxen.saxpath,
org.apache.xerces.util,
org.apach
e.xpath.patterns,
com.ibm.icu.math,
com.ibm.icu.text,
junit.runner,
org.a
pache.xpath.res,
com.ibm.icu.impl.data.icudt38b.translit,
javax.xml.par
sers,
org.apache.xerces.jaxp,
nu.xom.xinclude,
org.apache.xml.dtm,
org.ap
ache.bcel.verifier.structurals,
javax.xml.transform.stream,
org.dom4j.p
ersistence,
org.dom4j.dom,
org.apache.xalan.xsltc.compiler.util,
org.jun
it.internal,
org.apache.xalan.xsltc.runtime,
org.apache.html.dom,
org.do
m4j.io,
org.apache.xalan.xslt,
org.dom4j.swing,
org.apache.xerces.impl.x
s.util,
org.w3c.dom.stylesheets,
org.apache.xerces.impl,
com.ibm.icu.imp
l,
org.apache.xpath.axes,
org.junit.experimental.theories.suppliers,
org
.apache.xerces.xs,
javax.xml.bind.util,
org.junit.experimental.theories
,
com.ibm.icu.impl.duration.impl.data,
org.apache.xml.utils,
com.ibm.icu
.lang,
org.apache.xalan.serialize,
org.apache.xerces.impl.xs.models,
org
.apache.xalan.res,
org.xml.sax.ext,
org.xml.sax.helpers,
org.apache.xerc
es.xni.grammars,
org.apache.xerces.impl.xs,
org.apache.xpath.operations
,
javax.xml.bind,
org.dom4j.rule,
org.apache.xalan.extensions,
org.dom4j.
rule.pattern,
org.w3c.dom.ls,
org.apache.bcel,
org.junit.experimental.th
eories.internal,
org.apache.xerces.parsers,
org.apache.xalan.xsltc.cmdl
ine.getopt,
org.apache.xml.utils.res,
org.apache.xerces.xni.parser,
org.
apache.xalan.xsltc.trax,
org.apache.bcel.generic,
org.apache.xerces.imp
l.dv.xs,
com.ibm.icu.impl.data,
nu.xom.xslt,
org.apache.xml.res,
org.jaxe
n.function.xslt,
org.apache.xerces.impl.xpath.regex,
org.jaxen.dom.html
,
org.apache.xalan.templates,
org.apache.xalan.xsltc,
org.hamcrest.core,
org.hamcrest,
com.ibm.icu.impl.data.icudt38b.coll,
org.apache.xerces.im
pl.dv.util,
org.w3c.dom.views,
org.dom4j.xpp,
org.apache.xerces.impl.xs.
opti,
junit.extensions,
org.apache.xerces.impl.io,
org.apache.xerces.imp
l.dv.dtd,
junit.textui,
org.apache.xpath.compiler,
com.ibm.icu.impl.data
.icudt38b.brkitr,
org.apache.wml.dom,
org.apache.bcel.util,
org.apache.x
erces.impl.xs.identity,
javax.xml.transform.dom,
org.w3c.dom.traversal,
org.dom4j,
org.apache.xerces.dom3,
org.jaxen.javabean,
javax.xml.bind.he
lpers,
org.apache.xmlcommons,
org.jaxen.util,
org.dom4j.jaxb,
org.junit.m
atchers,
org.apache.wml,
com.gestalt.soakit.core.internals,
org.apache.b
cel.verifier.exc,
com.gestalt.soakit.core,
org.jaxen.function,
com.ibm.i
cu.impl.duration,
org.junit.runners,
org.apache.xpath.functions,
org.apa
che.xml.dtm.ref,
org.apache.xalan.xsltc.util,
org.apache.xalan.transfor
mer,
org.junit.experimental.results,
org.apache.bcel.classfile,
org.apac
he.xerces.dom3.bootstrap,
org.junit.runner.notification,
javax.xml.tran
sform,
org.apache.xerces.impl.dtd,
org.dom4j.xpath,
org.junit.internal.r
equests,
org.w3c.dom.css,
org.jaxen.dom4j,
org.apache.xerces.impl.dv,
org
.apache.xerces.dom3.as,
org.apache.xalan.processor,
org.apache.xpath,
or
g.dom4j.dtd,
com.ibm.icu.util,
org.apache.xerces.xni,
org.junit.runner,
o
rg.dom4j.datatype,
nu.xom.converters,
org.apache.xalan,
nu.xom.canonical
,
org.apache.xerces.dom.events,
org.w3c.dom.html,
org.apache.xalan.xsltc
.runtime.output,
org.jaxen.expr,
org.apache.xerces.xinclude,
lib,
org.apa
che.xerces.impl.xpath,
org.junit.runner.manipulation,
org.apache.xalan.
xsltc.dom,
org.apache.regexp,
org.apache.xalan.client,
org.jaxen.pattern
,
license,
org.apache.xalan.xsltc.cmdline,
org.apache.xml.dtm.ref.dom2dt
m,
org.w3c.dom.ranges,
org.dom4j.bean,
org.jaxen.jdom,
org.apache.xpath.d
omapi,
org.apache.xerces.impl.validation,
org.apache.bcel.verifier,
org.
jaxen.function.ext,
org.jaxen.saxpath.base,
org.apache.xerces.impl.dtd.
models,
org.dom4j.tree,
org.jaxen.dom,
org.dom4j.util,
org.junit.internal
.runners,
org.jaxen,
java_cup.runtime,
org.apache.xpath.objects,
org.apac
he.bcel.verifier.statics,
org.apache.xalan.lib,
org.jaxen.expr.iter,
org
.apache.xerces.impl.msg,
org.apache.xalan.trace,
org.apache.xml.seriali
zer,
nu.xom.tests,
org.xml.sax,
org.apache.xerces.dom,
org.hamcrest.inter
nal,
org.apache.xml.dtm.ref.sax2dtm,
org.junit,
org.apache.xalan.lib.sql
,
org.apache.xml.serialize,
org.w3c.dom,
javax.xml,
com.ibm.icu.impl.dura
tion.impl,
org.jaxen.xom,
javax.xml.transform.sax,
org.jaxen.saxpath.hel
pers,
org.w3c.dom.xpath,
junit.framework
Originally-Created-By: Apache Maven Bundle Plugin
Bundle-ManifestVersion: 2
Bundle-SymbolicName: soakit.test
Tool: Bnd-0.0.295
Embed-Dependency: *;scope=compile|runtime;inline=false
If I now launch eclipse and open that same file in the dependencies GUI
pane, I see the bizarre packages and no soakit.core. I delete the
strays, add soakit.core, clear out the strays on Runtime/Classpath, and
use Overview/Organize Manifests Wizard, and wind up with something that
looks pretty reasonable:
Manifest-Version: 1.0
Built-By: bradcox
Bundle-Activator: com.gestalt.soakit.test.TestActivator
Created-By: Apache Maven Bundle Plugin
Import-Package: com.gestalt.soakit.core;version="1.0.0.SNAPSHOT",
com.gestalt.soakit.core.internals;version="1.0.0.SNAPSHOT",
com.gestalt.soakit.test;version="1.0";resolution:=optional,
com.gestalt.soakit.test.internals;version="1.0";resolution:=optional
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Embed-Transitive: true
Bnd-LastModified: 1229859848087
Export-Package: com.gestalt.soakit.test;uses:="com.gestalt.soakit.test
.internals,
org.osgi.framework";version="1.0.0.SNAPSHOT",
com.gestalt.s
oakit.test.internals;uses:="org.osgi.framework,
com.gestalt.soakit.tes
t";version="1.0.0.SNAPSHOT"
Bundle-Version: 1.0.0.SNAPSHOT
Bundle-Name: soakit.test
Bundle-Description: Integration tests for soakit core and components
Bundle-ClassPath: .
Build-Jdk: 1.5.0_16
Private-Package: nu.xom,
org.apache.xalan.xsltc.compiler,
com.ibm.icu.im
pl.data.icudt38b,
javax.xml.namespace,
com.ibm.icu.impl.data.icudt38b.r
bnf,
org.w3c.dom.events,
org.apache.xerces.impl.xs.traversers,
org.dom4j
.persistence.nativ,
org.jaxen.saxpath,
org.apache.xerces.util,
org.apach
e.xpath.patterns,
com.ibm.icu.math,
com.ibm.icu.text,
junit.runner,
org.a
pache.xpath.res,
com.ibm.icu.impl.data.icudt38b.translit,
javax.xml.par
sers,
org.apache.xerces.jaxp,
nu.xom.xinclude,
org.apache.xml.dtm,
org.ap
ache.bcel.verifier.structurals,
javax.xml.transform.stream,
org.dom4j.p
ersistence,
org.dom4j.dom,
org.apache.xalan.xsltc.compiler.util,
org.jun
it.internal,
org.apache.xalan.xsltc.runtime,
org.apache.html.dom,
org.do
m4j.io,
org.apache.xalan.xslt,
org.dom4j.swing,
org.apache.xerces.impl.x
s.util,
org.w3c.dom.stylesheets,
org.apache.xerces.impl,
com.ibm.icu.imp
l,
org.apache.xpath.axes,
org.junit.experimental.theories.suppliers,
org
.apache.xerces.xs,
javax.xml.bind.util,
org.junit.experimental.theories
,
com.ibm.icu.impl.duration.impl.data,
org.apache.xml.utils,
com.ibm.icu
.lang,
org.apache.xalan.serialize,
org.apache.xerces.impl.xs.models,
org
.apache.xalan.res,
org.xml.sax.ext,
org.xml.sax.helpers,
org.apache.xerc
es.xni.grammars,
org.apache.xerces.impl.xs,
org.apache.xpath.operations
,
javax.xml.bind,
org.dom4j.rule,
org.apache.xalan.extensions,
org.dom4j.
rule.pattern,
org.w3c.dom.ls,
org.apache.bcel,
org.junit.experimental.th
eories.internal,
org.apache.xerces.parsers,
org.apache.xalan.xsltc.cmdl
ine.getopt,
org.apache.xml.utils.res,
org.apache.xerces.xni.parser,
org.
apache.xalan.xsltc.trax,
org.apache.bcel.generic,
org.apache.xerces.imp
l.dv.xs,
com.ibm.icu.impl.data,
nu.xom.xslt,
org.apache.xml.res,
org.jaxe
n.function.xslt,
org.apache.xerces.impl.xpath.regex,
org.jaxen.dom.html
,
org.apache.xalan.templates,
org.apache.xalan.xsltc,
org.hamcrest.core,
org.hamcrest,
com.ibm.icu.impl.data.icudt38b.coll,
org.apache.xerces.im
pl.dv.util,
org.w3c.dom.views,
org.dom4j.xpp,
org.apache.xerces.impl.xs.
opti,
junit.extensions,
org.apache.xerces.impl.io,
org.apache.xerces.imp
l.dv.dtd,
junit.textui,
org.apache.xpath.compiler,
com.ibm.icu.impl.data
.icudt38b.brkitr,
org.apache.wml.dom,
org.apache.bcel.util,
org.apache.x
erces.impl.xs.identity,
javax.xml.transform.dom,
org.w3c.dom.traversal,
org.dom4j,
org.apache.xerces.dom3,
org.jaxen.javabean,
javax.xml.bind.he
lpers,
org.apache.xmlcommons,
org.jaxen.util,
org.dom4j.jaxb,
org.junit.m
atchers,
org.apache.wml,
com.gestalt.soakit.core.internals,
org.apache.b
cel.verifier.exc,
com.gestalt.soakit.core,
org.jaxen.function,
com.ibm.i
cu.impl.duration,
org.junit.runners,
org.apache.xpath.functions,
org.apa
che.xml.dtm.ref,
org.apache.xalan.xsltc.util,
org.apache.xalan.transfor
mer,
org.junit.experimental.results,
org.apache.bcel.classfile,
org.apac
he.xerces.dom3.bootstrap,
org.junit.runner.notification,
javax.xml.tran
sform,
org.apache.xerces.impl.dtd,
org.dom4j.xpath,
org.junit.internal.r
equests,
org.w3c.dom.css,
org.jaxen.dom4j,
org.apache.xerces.impl.dv,
org
.apache.xerces.dom3.as,
org.apache.xalan.processor,
org.apache.xpath,
or
g.dom4j.dtd,
com.ibm.icu.util,
org.apache.xerces.xni,
org.junit.runner,
o
rg.dom4j.datatype,
nu.xom.converters,
org.apache.xalan,
nu.xom.canonical
,
org.apache.xerces.dom.events,
org.w3c.dom.html,
org.apache.xalan.xsltc
.runtime.output,
org.jaxen.expr,
org.apache.xerces.xinclude,
lib,
org.apa
che.xerces.impl.xpath,
org.junit.runner.manipulation,
org.apache.xalan.
xsltc.dom,
org.apache.regexp,
org.apache.xalan.client,
org.jaxen.pattern
,
license,
org.apache.xalan.xsltc.cmdline,
org.apache.xml.dtm.ref.dom2dt
m,
org.w3c.dom.ranges,
org.dom4j.bean,
org.jaxen.jdom,
org.apache.xpath.d
omapi,
org.apache.xerces.impl.validation,
org.apache.bcel.verifier,
org.
jaxen.function.ext,
org.jaxen.saxpath.base,
org.apache.xerces.impl.dtd.
models,
org.dom4j.tree,
org.jaxen.dom,
org.dom4j.util,
org.junit.internal
.runners,
org.jaxen,
java_cup.runtime,
org.apache.xpath.objects,
org.apac
he.bcel.verifier.statics,
org.apache.xalan.lib,
org.jaxen.expr.iter,
org
.apache.xerces.impl.msg,
org.apache.xalan.trace,
org.apache.xml.seriali
zer,
nu.xom.tests,
org.xml.sax,
org.apache.xerces.dom,
org.hamcrest.inter
nal,
org.apache.xml.dtm.ref.sax2dtm,
org.junit,
org.apache.xalan.lib.sql
,
org.apache.xml.serialize,
org.w3c.dom,
javax.xml,
com.ibm.icu.impl.dura
tion.impl,
org.jaxen.xom,
javax.xml.transform.sax,
org.jaxen.saxpath.hel
pers,
org.w3c.dom.xpath,
junit.framework
Originally-Created-By: Apache Maven Bundle Plugin
Bundle-ManifestVersion: 2
Bundle-SymbolicName: soakit.test
Tool: Bnd-0.0.295
Embed-Dependency: *;scope=compile|runtime;inline=false
But as soon as I do a full build to get something executable (I've given
up on getting eclipse to build anything executable until somebody
provides the secret sauce), maven overwrites this with the invalid version.
I think what's going on is that maven's manifest prevails so test is
getting soakit.core from two places. Based on that, I'll try reworking
the pom to remove any ambiguity. Could really use any suggestions on that.
But even more, I could really use a better understanding of why maven
and eclipse aren't working together now, and a fool proof recipe for how
to make them coexist going forward.
I've also tried Netbeans and IntelliJ but these all fail for various
reasons (bnd runs out of memory in IntelliJ building soakit.core for
one). Using Pax-Runner fails running some Eclipse ant script trying to
read bizarre directories. Every environ fails with a different problem.
The only common factor is my busted mental model of how maven and
eclipse work together. Can someone set me straight? Here's my (no doubt)
busted pom:
<?xml version="1.0" encoding="utf-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<groupId>soakit</groupId>
<artifactId>soakit.test</artifactId>
<version>1.0-SNAPSHOT</version>
<name>soakit.test</name>
<description>Integration tests for soakit core and components</description>
<packaging>bundle</packaging>
<parent>
<groupId>soakit</groupId>
<artifactId>soakit</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>soakit</groupId>
<artifactId>soakit.core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
<!--
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.5.0-SNAPSHOT</version>
<extensions>true</extensions>
<configuration>
<manifestLocation>src/main/resources/META-INF</manifestLocation>
<instructions>
<Bundle-Version>${pom.version}</Bundle-Version>
<Bundle-SymbolicName>soakit.test</Bundle-SymbolicName>
<Bundle-RequiredExecutionEnvironment>
J2SE-1.5
</Bundle-RequiredExecutionEnvironment>
<Bundle-Activator>
com.gestalt.soakit.test.TestActivator
</Bundle-Activator>
<Export-Package>
com.gestalt.soakit.test.*;version="${pom.version}",
</Export-Package>
<Import-Package>
*;resolution:=optional
</Import-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
<executions>
<execution>
<id>manifest</id>
<goals>
<goal>manifest</goal>
</goals>
<phase>process-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Richard S. Hall wrote:
> Try printing CoreFactoryImpl.class.getClassLoader() within your bundle
> using the service tracker and then print cso.getClass().getClassLoader()
> from the service object and see if they are coming from the same class
> loader.
>
> One thing that seems weird to me, why are you casting to CoreFactoryImpl
> instead of CoreFactory?
>
> -> richard
>
> Brad Cox wrote:
>> For the life of me I can't see why this fails. Here's the runup in
>> detail:
>>
>> coreTracker is a ServiceTracker for CoreServiceImpl, defined in a
>> bundle I'm trying to access from the integration test bundle. These
>> are the relevant declarations:
>>
>> public interface CoreFactory extends ServiceFactory
>> public class CoreFactoryImpl implements CoreFactory
>>
>> Integration test uses a ServiceTracker (CoreTracker) to locate the
>> sole core instance from the core bundle like this:
>>
>> Object cso = coreTracker.getService();
>> System.out.println("cso:"+cso);
>> > cso:com.gestalt.soakit.core.internals.CoreFactoryImpl@dead19
>>
>> So why should this cast fails with a ClassCastException?
>> CoreFactoryImpl cs = (CoreFactoryImpl)cso;
>>
>> I'm going blind from staring at this. Maybe someone can spot what I'm
>> missing. Here's some more detail.
>>
>> Class csoClass = cso.getClass();
>> System.out.println("csoClass:"+csoClass);
>> > csoClass:com.gestalt.soakit.core.internals.CoreFactoryImpl
>>
>> Class[] csoClasses = csoClass.getClasses();
>> System.out.println("cso.getClasses():"+csoClass.getClasses());
>> > cso.getClasses():[Ljava.lang.Class;@1cc5ef
>>
>> Class[] csoInterfaces = csoClass.getInterfaces();
>> System.out.println("cso.getInterfaces():"+csoClass.getInterfaces());
>> > cso.getInterfaces():[Ljava.lang.Class;@c44af4
>>
>> Here's the full trace
>>
>> > org.osgi.framework.BundleException: Activator start error in bundle
>> soakit.test [24].
>> > at org.apache.felix.framework.Felix._startBundle(Felix.java:1701)
>> > at org.apache.felix.framework.Felix.startBundle(Felix.java:1578)
>> > at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:382)
>> > at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:363)
>> > at
>> org.apache.felix.shell.impl.StartCommandImpl.execute(StartCommandImpl.java:82)
>>
>> > at
>> org.apache.felix.shell.impl.Activator$ShellServiceImpl.executeCommand(Activator.java:276)
>>
>> > at
>> org.apache.felix.shell.tui.Activator$ShellTuiRunnable.run(Activator.java:167)
>>
>> > at java.lang.Thread.run(Thread.java:613)
>> > Caused by: java.lang.ClassCastException:
>> com.gestalt.soakit.core.internals.CoreFactoryImpl
>> > at
>> com.gestalt.soakit.test.internals.TestImpl.configure(TestImpl.java:49)
>> > at
>> com.gestalt.soakit.test.internals.TestFactoryImpl.createTest(TestFactoryImpl.java:35)
>>
>> > at
>> com.gestalt.soakit.test.TestActivator.start(TestActivator.java:54)
>> > at
>> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
>>
>> > at org.apache.felix.framework.Felix._startBundle(Felix.java:1654)
>> > ... 7 more
>> > java.lang.ClassCastException:
>> com.gestalt.soakit.core.internals.CoreFactoryImpl
>>
>>
>> ------------------------------------------------------------------------
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
Re: ClassCastException after ServiceTracker.getService()??
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Try printing CoreFactoryImpl.class.getClassLoader() within your bundle
using the service tracker and then print cso.getClass().getClassLoader()
from the service object and see if they are coming from the same class
loader.
One thing that seems weird to me, why are you casting to CoreFactoryImpl
instead of CoreFactory?
-> richard
Brad Cox wrote:
> For the life of me I can't see why this fails. Here's the runup in
> detail:
>
> coreTracker is a ServiceTracker for CoreServiceImpl, defined in a
> bundle I'm trying to access from the integration test bundle. These
> are the relevant declarations:
>
> public interface CoreFactory extends ServiceFactory
> public class CoreFactoryImpl implements CoreFactory
>
> Integration test uses a ServiceTracker (CoreTracker) to locate the
> sole core instance from the core bundle like this:
>
> Object cso = coreTracker.getService();
> System.out.println("cso:"+cso);
> > cso:com.gestalt.soakit.core.internals.CoreFactoryImpl@dead19
>
> So why should this cast fails with a ClassCastException?
> CoreFactoryImpl cs = (CoreFactoryImpl)cso;
>
> I'm going blind from staring at this. Maybe someone can spot what I'm
> missing. Here's some more detail.
>
> Class csoClass = cso.getClass();
> System.out.println("csoClass:"+csoClass);
> > csoClass:com.gestalt.soakit.core.internals.CoreFactoryImpl
>
> Class[] csoClasses = csoClass.getClasses();
> System.out.println("cso.getClasses():"+csoClass.getClasses());
> > cso.getClasses():[Ljava.lang.Class;@1cc5ef
>
> Class[] csoInterfaces = csoClass.getInterfaces();
> System.out.println("cso.getInterfaces():"+csoClass.getInterfaces());
> > cso.getInterfaces():[Ljava.lang.Class;@c44af4
>
> Here's the full trace
>
> > org.osgi.framework.BundleException: Activator start error in bundle
> soakit.test [24].
> > at org.apache.felix.framework.Felix._startBundle(Felix.java:1701)
> > at org.apache.felix.framework.Felix.startBundle(Felix.java:1578)
> > at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:382)
> > at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:363)
> > at
> org.apache.felix.shell.impl.StartCommandImpl.execute(StartCommandImpl.java:82)
>
> > at
> org.apache.felix.shell.impl.Activator$ShellServiceImpl.executeCommand(Activator.java:276)
>
> > at
> org.apache.felix.shell.tui.Activator$ShellTuiRunnable.run(Activator.java:167)
>
> > at java.lang.Thread.run(Thread.java:613)
> > Caused by: java.lang.ClassCastException:
> com.gestalt.soakit.core.internals.CoreFactoryImpl
> > at
> com.gestalt.soakit.test.internals.TestImpl.configure(TestImpl.java:49)
> > at
> com.gestalt.soakit.test.internals.TestFactoryImpl.createTest(TestFactoryImpl.java:35)
>
> > at
> com.gestalt.soakit.test.TestActivator.start(TestActivator.java:54)
> > at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
>
> > at org.apache.felix.framework.Felix._startBundle(Felix.java:1654)
> > ... 7 more
> > java.lang.ClassCastException:
> com.gestalt.soakit.core.internals.CoreFactoryImpl
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org