Question: I have a question about declarative OSGi Services. I have the following interface : 

```
  public interface PrintService {
    public void print();
  }

```

and its implementation: 

```
    public class PrintServiceImpl implements PrintService {

      @Override
      public void print() {
        System.out.println("Hello from PrintServiceImpl!");
      }
    }

```

OSGI-INF/component.xml :

```
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="service">
   <implementation class="service.PrintServiceImpl"/>
   <service>
      <provide interface="print.PrintService"/>
   </service>
</scr:component>

```

MANIFEST.MF :

```
Service-Component: OSGI-INF/component.xml

```

After I install the service and start it nothing happend. How can I activate it and print "*Hello from PrintServiceImpl!*" to console.

Answer: 
All the answers above are correct. Now to have something like printing something on the shell you could write something like:

```
public interface PrintService {
    public void print();
}

```

Implentation:

```
public class PrintServiceImpl implements PrintService {

      @Override
      public void print() {
        System.out.println("Hello from PrintServiceImpl!");
      }
}

```

component.xml:

```
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="service">
   <implementation class="service.PrintServiceImpl"/>
   <service>
      <provide interface="print.PrintService"/>
   </service>
</scr:component>

```

And now you could use a Command to call your print method:

```
public class PrintCommand implements Command {

    private PrintService printer;

    public void setPrinter(PrintService printer) {
        this.printer = printer; 
    }

    public void unsetPrinter(PrintService printer) {
        this.printer = null;
    }

    @Override
    public void execute(String line, PrintStream arg1, PrintStream arg2) {    
        printer.print();
    }

    @Override
    public String getName() {
        return "print";
    }

    @Override
    public String getShortDescription() {
        return "just a printer";
    }

    @Override
    public String getUsage() {
        return "print";
    }

}

```

And your component.xml should have a new entry:

```
<component name="PrintCommand">
    <implementation class="PrintCommand"/>
    <service>
        <provide interface="org.apache.felix.shell.Command"/>
    </service>
    <reference
        name="printer"
        interface="PrintService"
        bind="setPrinter"
        unbind="unsetPrinter"
        cardinality="1..1"
        policy="static"
    />
</component>

```

The Command Interface is part of Apache Felix Shell and if you now run Felix and type `help` in your console you will see all registered commands and there is the PrintCommand as well `print`. If you now type print in the shell you will see the text.
When you are use annotations, XML file will be generated automatically under OSGI-INF/... folder. 

```
  public interface PrintService {
    public void print();
  }

  implementation with annotations: 

  @Component(service = PrintService.class)
  public class PrintServiceImpl implements PrintService {

      @Activate
      public void activate() {
         print();
      }

      @Override
      public void print() {
        System.out.println("Hello from PrintServiceImpl!");
      }
    }

```

As i said before, XML file created automatically. With @Component(service = PrintService.class) annotations, we register PrintService to OSGi framework(like registerService method in ServiceTracker). When service is registered, Activate method will be called. Method name can be anything. Just add @Activate annotations to say "when service is registered, call the method which is under @Activate annotations" to OSGi Framework.