Hi Erwin,

you have the @Reference annotation in command: org.apache.karaf.shell.api.action.lifecycle.Reference

Same usage as in SCR.

Regards
JB

On 04/13/2016 10:38 PM, Erwin Müller wrote:
Thank you,

but how can I inject services like I do in SCR? Or do I need that to do
manually via the BundleContext?

-------
       @Reference
       private ParserService parseService;
-------

Regards, Erwin.


On Wednesday, April 13, 2016 08:57:47 PM Jean-Baptiste Onofré wrote:
Hi,

You don't need SCR if you use the command annotation.

Just use the plugin:

              <plugin>
                  <groupId>org.apache.karaf.tooling</groupId>
                  <artifactId>karaf-services-maven-plugin</artifactId>
              </plugin>


And no need to use @Component.

Regards
JB

On 04/13/2016 08:49 PM, Erwin Müller wrote:
Hello,

I setup an OSGi application with Felix SCR and Karaf. But how can I use
the
SCR annotations for Karaf commands? I tried the example command from the
Karaf manual and it works fine, but if I add the Felix SCR annotations,
the command is not working anymore in Karaf.

I'm pretty new to OSGi but I got everything working (Karaf, Pax Exam,
Sling), I'm only stuck

----------
@Command(scope = "sscontrol", name = "parse", description = "Parses the
specified resource and checks for eventual errors.")
@Service
@Component
public class ParseCommand implements Action {

      @Argument(name = "resource", description = "The resource URI to be

parsed.", required = true, multiValued = false)

      private String resource;

      @Reference
      private ParserService parseService;

      @Override
      public Object execute() throws Exception {

          Parser parser = parseService.create();
          SscontrolScript script = parser.parse(toUri(resource));
          return script;

      }

      private URI toUri(String resource) throws URISyntaxException {

          return new URI(resource);

      }

}
--------


--
Jean-Baptiste Onofré
[email protected]
http://blog.nanthrax.net
Talend - http://www.talend.com

Reply via email to