You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@karaf.apache.org by rcbandit <pe...@gmail.com> on 2014/09/25 19:38:22 UTC

Configure multiple custom commands in Karaf

I successfully created custom command for Karaf shell. Now I would like to
create multiple commends and shrink them into one Java file and xml. I
tested this example but it's not working:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
        <command>
            <action class="org.apache.karaf.demos.command.MyCommand"/>
            <completers>
                <ref component-id="myCompleter"/>
                <null/>
            </completers>
        </command>
        <command>
            <action class="org.apache.karaf.demos.command.MyCommandSec"/>
            <completers>
                <ref component-id="myCompleterSec"/>
                <null/>
            </completers>
        </command>
    </command-bundle>
    <bean id="myCompleter"
class="org.apache.karaf.demos.command.MyCompleter"/>
    <bean id="myCompleterSec"
class="org.apache.karaf.demos.command.MyCommandSec"/>
</blueprint>

import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;

@Command(scope = "kernel", name = "create", description="Says hello")
public class MyCommand extends OsgiCommandSupport {

    @Argument(index = 0, name = "arg", description = "The command argument",
required = false, multiValued = false)
    String arg = null;

    @Override
    protected Object doExecute() throws Exception {
        System.out.println("Executing My Command Demo");
        return null;
    }
}


This in not working, I get exception. Can you tell me what is the proper way
to do this?




--
View this message in context: http://karaf.922171.n3.nabble.com/Configure-multiple-custom-commands-in-Karaf-tp4035524.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: Configure multiple custom commands in Karaf

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Take a look in Karaf commands itself.

For instance:

https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=tree;f=jdbc/command;h=db0b154be89ed7374d6f0d51edc1f7d846e4310c;hb=karaf-3.0.x

Regards
JB

On 09/25/2014 08:19 PM, rcbandit wrote:
> Yes this is what I want to do. Can you show me how?
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Configure-multiple-custom-commands-in-Karaf-tp4035524p4035526.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Configure multiple custom commands in Karaf

Posted by rcbandit <pe...@gmail.com>.
Yes this is what I want to do. Can you show me how?



--
View this message in context: http://karaf.922171.n3.nabble.com/Configure-multiple-custom-commands-in-Karaf-tp4035524p4035526.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: Configure multiple custom commands in Karaf

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi you might shrink it to one XML file but you'll need one class for every
command, and one class for every completer.

regards, Achim

sent from mobile device
Am 25.09.2014 19:40 schrieb "rcbandit" <pe...@gmail.com>:

> I successfully created custom command for Karaf shell. Now I would like to
> create multiple commends and shrink them into one Java file and xml. I
> tested this example but it's not working:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>     <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
>         <command>
>             <action class="org.apache.karaf.demos.command.MyCommand"/>
>             <completers>
>                 <ref component-id="myCompleter"/>
>                 <null/>
>             </completers>
>         </command>
>         <command>
>             <action class="org.apache.karaf.demos.command.MyCommandSec"/>
>             <completers>
>                 <ref component-id="myCompleterSec"/>
>                 <null/>
>             </completers>
>         </command>
>     </command-bundle>
>     <bean id="myCompleter"
> class="org.apache.karaf.demos.command.MyCompleter"/>
>     <bean id="myCompleterSec"
> class="org.apache.karaf.demos.command.MyCommandSec"/>
> </blueprint>
>
> import org.apache.karaf.shell.commands.Argument;
> import org.apache.karaf.shell.commands.Command;
> import org.apache.karaf.shell.console.OsgiCommandSupport;
>
> @Command(scope = "kernel", name = "create", description="Says hello")
> public class MyCommand extends OsgiCommandSupport {
>
>     @Argument(index = 0, name = "arg", description = "The command
> argument",
> required = false, multiValued = false)
>     String arg = null;
>
>     @Override
>     protected Object doExecute() throws Exception {
>         System.out.println("Executing My Command Demo");
>         return null;
>     }
> }
>
>
> This in not working, I get exception. Can you tell me what is the proper
> way
> to do this?
>
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Configure-multiple-custom-commands-in-Karaf-tp4035524.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

Re: Configure multiple custom commands in Karaf

Posted by maroshi <ye...@yahoo.com>.
You assigned the completer to the MyCommandSec as MyCommandSec. This is
illegal since completers do not extend OsgiCommandSupport.





--
View this message in context: http://karaf.922171.n3.nabble.com/Configure-multiple-custom-commands-in-Karaf-tp4035524p4035745.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.