Return-Path: X-Original-To: apmail-karaf-user-archive@minotaur.apache.org Delivered-To: apmail-karaf-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0788B18180 for ; Wed, 6 Jan 2016 08:18:55 +0000 (UTC) Received: (qmail 3121 invoked by uid 500); 6 Jan 2016 08:18:54 -0000 Delivered-To: apmail-karaf-user-archive@karaf.apache.org Received: (qmail 3076 invoked by uid 500); 6 Jan 2016 08:18:54 -0000 Mailing-List: contact user-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@karaf.apache.org Delivered-To: mailing list user@karaf.apache.org Received: (qmail 3066 invoked by uid 99); 6 Jan 2016 08:18:54 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jan 2016 08:18:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id D01F0C02C7 for ; Wed, 6 Jan 2016 08:18:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.001 X-Spam-Level: * X-Spam-Status: No, score=1.001 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id HNwW8lMJtMNo for ; Wed, 6 Jan 2016 08:18:42 +0000 (UTC) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id CE012203B7 for ; Wed, 6 Jan 2016 08:18:41 +0000 (UTC) Received: from mfilter33-d.gandi.net (mfilter33-d.gandi.net [217.70.178.164]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 59FAE1720BE for ; Wed, 6 Jan 2016 09:18:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter33-d.gandi.net Received: from relay4-d.mail.gandi.net ([IPv6:::ffff:217.70.183.196]) by mfilter33-d.gandi.net (mfilter33-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id mVwPDwQ3VOnz for ; Wed, 6 Jan 2016 09:18:33 +0100 (CET) X-Originating-IP: 82.238.224.4 Received: from [192.168.134.10] (bre91-1-82-238-224-4.fbx.proxad.net [82.238.224.4]) (Authenticated sender: jb@nanthrax.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id D67721720AF for ; Wed, 6 Jan 2016 09:18:33 +0100 (CET) Subject: Re: Null service in Karaf command To: user@karaf.apache.org References: <568CB82C.70607@nanthrax.net> <9f43cfa0eecc5a307286f93f33dfdd0d@petinou.fr> From: =?UTF-8?Q?Jean-Baptiste_Onofr=c3=a9?= Message-ID: <568CCDD9.30400@nanthrax.net> Date: Wed, 6 Jan 2016 09:18:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <9f43cfa0eecc5a307286f93f33dfdd0d@petinou.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit No problem, you're welcome ;) On 01/06/2016 09:04 AM, ben@petinou.fr wrote: > It works! > > Thank you very much! > > Le 06.01.2016 07:46, Jean-Baptiste Onofré a écrit : >> You should not mix DS and Karaf shell API in the same bundle (it's one >> or the other). >> >> So, you should have: >> >> import org.apache.karaf.shell.api.action.Action; >> import org.apache.karaf.shell.api.action.lifecycle.Reference; >> import org.apache.karaf.shell.api.action.lifecycle.Service; >> import org.apache.karaf.shell.api.action.Command; >> >> @Command(scope = "myscope", name = "myCmd", description = "desc") >> @Service >> public class MyCmd implements Action { >> >> @Reference >> private Model model; >> >> @Override >> public Object execute() throws Exception { >> ... >> } >> >> } >> >> And you just use the Karaf command plugin: >> >> >> org.apache.karaf.tooling >> karaf-services-maven-plugin >> 4.0.3 >> >> >> service-metadata-generate >> process-classes >> >> service-metadata-generate >> >> >> >> >> >> >> No need to use DS in the command. >> >> Regards >> JB >> >> On 01/05/2016 09:30 PM, ben@petinou.fr wrote: >>> Hi everyone, >>> >>> I'm trying to create a Karaf Command that uses one of my services (via >>> Declarative Services configured with maven-bundle-plugin). >>> >>> Here is my Karaf command: >>> >>> @Command(scope = "myscope", name = "myCmd", description = "desc") >>> @Service >>> @Component(immediate = true) >>> public class MyCmd implements Action { >>> /** Reference to the model. */ >>> private Model model; >>> >>> @Override >>> public Object execute() throws Exception { >>> System.out.println("Model: " + model); >>> return null; >>> } >>> >>> @Reference >>> public void setModel(final Model modelToSet) { >>> System.out.println("MyCmd.setModel: " + modelToSet); >>> model = modelToSet; >>> } >>> >>> public void unsetModel(final Model modelToSet) { >>> System.out.println("MyCmd.unsetModel"); >>> model = null; >>> } >>> } >>> >>> When I start Karaf, I have the following output in the console: >>> MyCmd.setModel: ModelImpl@23623746 >>> >>> But when I call the command, the model is null... >>> karaf@root()> myscope:myCmd >>> Model: null >>> >>> I guess there is something wrong with how Karaf creates the commands (I >>> guess the commands are instantiated each time they are called from the >>> console). >>> >>> I just declared the ModelImpl class with @Component (and it implements >>> my Model interface). >>> >>> How could I make it work? >>> >>> Kind regards, >>> >>> Ben -- Jean-Baptiste Onofré jbonofre@apache.org http://blog.nanthrax.net Talend - http://www.talend.com