2 Replies Latest reply on Jul 11, 2016 10:50 AM by Falco Thiel

    How to extend CLI with custom commands?

    Falco Thiel Newbie

      Hi,

      I want to extend the JBoss CLI with custom commands. I’m using WildFly 10.0.0.Final and launching it with standalone-full-ha.xml by using the Windows cmd.

      The instructions found on this site https://docs.jboss.org/author/display/WFLY10/CLI+extensibility+for+layered+products seemed to be just what I was searching for. So I created a small Maven project with a SimpleCommandHandler and SimpleCommandProvider class and also a Bean so I can see that my JAR is really loaded by the server. After this I created the needed META-INF data.

      test-cli-project.png

      My pom.xml looks like this:

      test-cli-project-pom.png

      I built the project and was able to successfully deploy it on the server. But the command was not available and it was not listed by “help --commands”.

      I also searched how the standard commands are loaded and found the BaseOperationCommand class. So I let my command handler extend from this class, but without success.

      Then I recognized that the org.jboss.as.cli extension is not in the extension list of standalone-full-ha.xml. Is it loaded implicitly through an other extension or do I have to add it to the extension list? I tried to add it like this:

       

      <extensions>
            …
            <extension module="org.jboss.as.cli"/>
            …

      </extensions>

       

      <profile>
            …
            <subsystem xmlns="urn:jboss:domain:cli:2.0"/>
            …
      </profile>

       

      But it didn’t work, the cli module could not be loaded. But also found that the module exists under \wildfly-10.0.0.Final\modules\system\layers\base\org\jboss\as\cli\main\, so my confusion grew.

      Or do I have to write a subsystem that includes the cli extension?

       

      Any help would be nice, thanks in advance.

        • 1. Re: How to extend CLI with custom commands?
          Tomaz Cerar Master

          What exactly does you CLI extension do? Is it a server side command? aka something does work on some subsystems.

          or actual high level command addon in CLI?

           

          As for CLI extensions go, you don't need to register them in standalone-*.xml files as there is where subsystems go.

          You do not deploy them as deployments, but you just need to make sure that CLI class loader sees the classes that is about it.

          1 of 1 people found this helpful
          • 2. Re: How to extend CLI with custom commands?
            Falco Thiel Newbie

            Tomaz Cerar schrieb:

            ...

            You do not deploy them as deployments, but you just need to make sure that CLI class loader sees the classes that is about it.

            This was a good hint and I found a solution that works for me. I just added the path to my JAR file to the resources in wildfly-10.0.0.Final\modules\system\layers\base\org\jboss\as\cli\main\module.xml and then I could use my the custom test command. When the CLI module is loaded all given resources in the module.xml are loaded, also my own classes, and they are found by initCommands() when called in the constructor of the CommandContextImpl class.

             

            The CLI extension doesn't really do anything yet, I'm just evaluating if and how it works.

             

            Thank You very much