-2

I am using felix osgi + ds + weld cdi + pax cdi. So I have the following service:

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ServiceScope;

@Component(
    immediate = false,
    property={"label=stub"},
    scope=ServiceScope.PROTOTYPE
)
public class ServiceImpl implements ServiceI{

    @Override
    public String getMyString() {
        Component t=null;
        return "This is my string:"+t;
    }

}

To generate ds.xml file I use maven-bundle-plugin as I know this is modern way of generating ds xml files. So everything seems to work. Ds xml file is generated by maven plugin and put into OSGI-INF. I decided to check what the felix will do if I delete this ds.xml file. So I deleted this xml file and cleaned the osgi cache. And I was very suprised with the results. The service still works and successfully injected. I just get message:Component descriptor entry 'OSGI-INF/....xml' not found. Besides I thought that @Component annotation is removed after compilation. That's why I didn't install org.osgi.service.component bundle in my osgi. However everything works fine and all bundles are resolved.

So the questions -

  1. why do DS services work without xml file?
  2. why my osgi framework doesn't need org.osgi.service.component.annotations.Component? Felix bundle has org.osgi.service.component.annotations package but not org.osgi.service.component.annotations.Component annotation.
Pavel_K
  • 10,748
  • 13
  • 73
  • 186

2 Answers2

2
  1. DS does NOT work without the xml file.

Probably you have deleted it from the file system, but not from the bundle that is deployed into the OSGi Framework.

  1. These annotations are build-time only, they do not create a runtime dependency.
Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • I've been using OSGi since 2004, I don't need to try. I don't know what exactly you are doing wrong but I guarantee that DS cannot work without the XML. – Neil Bartlett May 01 '16 at 13:23
  • Because the Service-Component header in the manifest points to a non-existent file. – Neil Bartlett May 01 '16 at 13:31
  • Sorry if I seem flippant, but I can't try right now. I know how DS works though, so I'm confident that you've made some mistake along the way. If you want to post your compete example project in a reproducible form, eg on Github, this would help. – Neil Bartlett May 01 '16 at 13:36
  • How are you deleting the XML in the JAR file... do you have a special tool for this or are you just rebuilding the project? After modifying the JAR do you type "update" in the OSGi shell? – Neil Bartlett May 01 '16 at 14:08
  • I'm unable to run this because it has dependencies that you have not included, specifically `javax.enterprise.context`, `javax.enterprise.event` and `org.ops4j.pax.cdi.api`. – Neil Bartlett May 01 '16 at 14:11
  • Oh yes I can build it no problem, because they are in central. But I have no idea how to run it. I don't think there is much point continuing this; I have given you an answer which remains correct to the best of my knowledge. – Neil Bartlett May 01 '16 at 14:17
  • Right. And the result was the error message you saw. I just don't see what is so mysterious about this. – Neil Bartlett May 01 '16 at 14:29
0

I must admit that Neil is right. The annotations are build time. Even if the Felix SCR guys would have done a coup and tried to do it runtime because the annotations have CLASS retention and are therefore not available to the runtime unless they parse the class files.

You must be seeing something else.

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55