0

I use apache felix and I have the following annotation for my DS

@Component(immediate = false,properties = {"name:String=stub"})

Maven generates the following xml

<component ...>
<implementation ..../>
<service>
....
</service>
<properties enty="name:String=stub"/>
</component>

However, when I start this bundle I get the following:

ERROR: com.temp.biz (55): General problem with descriptor entry '/OSGI-INF/com.temp.MyClass.xml'
org.apache.felix.scr.impl.parser.ParseException: Exception during parsing
    at org.apache.felix.scr.impl.metadata.XmlHandler.startElement(XmlHandler.java:364)
    at org.apache.felix.scr.impl.parser.KXml2SAXParser.parseXML(KXml2SAXParser.java:82)
    at org.apache.felix.scr.impl.BundleComponentActivator.loadDescriptor(BundleComponentActivator.java:245)
    at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:158)
    at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:120)
    at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:258)
    at org.apache.felix.scr.impl.Activator.access$000(Activator.java:45)
    at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:185)
    at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
    at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:479)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:414)
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:443)
    at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:913)

How to fix it? The problem disappears as soos as I remove properties from @Component.

Pavel_K
  • 10,748
  • 13
  • 73
  • 186

1 Answers1

2

For the OSGi DS @Component annotation, you want to use property:

@Component(immediate = false, property = {"name:String=stub"})

For the Felix SCR annotations, refer to the documentation.

Sean Bright
  • 118,630
  • 17
  • 138
  • 146
  • Thank you. Could you also provide an example for org.apache.felix.scr.annotations.Component ? – Pavel_K Jul 10 '15 at 14:11
  • Thanks. I've looked already the docs but I don't see there anything like property. Do you? – Pavel_K Jul 10 '15 at 14:14
  • You would use the [`@Property`](http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html#property) annotation. Ctrl-F in your browser and type "property." But again, you either use the OSGi annotations (preferred), the bnd annotations, or the Felix SCR annotations. Not a mixture of all of them. – Sean Bright Jul 10 '15 at 14:15
  • And the last - could you explain the difference between these two @Components. That was my problem at the core. – Pavel_K Jul 10 '15 at 14:18
  • I've been trying to, but I'm not sure you are reading. There are (at least) 3 different annotation libraries for OSGi Declarative Services. The [OSGi Declarative Services Annotations](https://osgi.org/javadoc/r5/cmpn/org/osgi/service/component/annotations/package-summary.html), the [bnd DS Annotations](http://www.aqute.biz/Bnd/Components), and the [Felix SCR Annotations](http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html). They all do fundamentally the same thing - they generate the DS XML files. You just have to pick one and use it. – Sean Bright Jul 10 '15 at 14:21
  • You make me laugh. I'm reading really. I've tried already osgi and apache `@Component`. I think the difference is that osgi `@Component` was developed by OSGI alliance and is interface. The apache's one is the felix implementation. But I want to be sure. – Pavel_K Jul 10 '15 at 14:25
  • The bnd and Felix SCR annotations existed before the OSGi Alliance released their own, but now that the OSGi ones are part of the specification, it only makes sense to use theirs. – Sean Bright Jul 10 '15 at 14:26
  • By the way could you explain the meaning of the & in @OsgiService (filter = "(&(name=stub))"), What is it for? Is it AND? Then why it's at the beginning? – Pavel_K Jul 10 '15 at 14:32
  • It's an LDAP filter which is what OSGi uses for various things. Do yourself a favor and pick up a copy of "OSGi In Action." The barrier to entry for OSGi has lowered in the past few years, but that book gives you a great foundation on how OSGi works. I'd also recommend you use Bndtools for OSGi development because it makes the whole process that much less painful. – Sean Bright Jul 10 '15 at 14:36
  • Thank you. You wouldn't believe, but I've read a few years ago that book. The problem is that there are too many fetures: javafx, cdi, osgi, ejb, mybatis, rmi, testing frameworks, databases, solr, elastic, redis etc and this is only java, without css,js etc. And besides I've passed LPIC2 so too many details already. – Pavel_K Jul 10 '15 at 14:40
  • By the way, you don't need to put `:String` in the property, as String is the default type. – Neil Bartlett Jul 10 '15 at 19:12