Connecting to the CLI

There are three ways to manage your WildFly, that is, by editing the XML file, the Console and the CLI.

  • First of all, editing the XML directly can be error-prone, as it can waste you precious seconds; moreover, every change requires a server restart.
  • The Console gives you visual editing features, but it's not complete. The Web Console can perform just a subset of all the available actions that you can execute using the CLI.
  • CLI stands for Command Line Interface, and it is a tool that you are recommended to use to manage your WildFly application server.

Why the CLI? Most of the time, for security reasons, you connect to enterprise environments via SSH and are thus not able to see the Web Console at all. CLI WildFly comes in handy for this purpose.

CLI is a powerful tool that gives you full control over WildFly; you can deploy and undeploy applications, create and manage data sources, manage logging, change system properties, stop and start instances, and more. Working with the CLI also helps you understand the WildFly core logic so you can really become an expert WildFly administrator. Nevertheless, if you really want a GUI as well, you can have the CLI in GUI version; just execute the following command while you have your WildFly running:

$ cd $WILDFLY_HOME
$ ./bin/jboss-cli.sh --gui

The following screenshot depicts the CLI GUI tool:

CLI GUI tool

Now, it's time to play around with the CLI. Let's see what you can do!

Getting ready

As the CLI is a management tool, you will need to have your WildFly instance up and running. In this case too, we will use the default standalone configuration.

Open a terminal window and start WildFly:

$ cd $WILDFLY_HOME
$ ./bin/standalone.sh
...
22:12:23,600 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 9.0.0.Beta2 (WildFly Core 1.0.0.Beta2) started in 3087ms - Started 202 of 379 services (210 services are lazy, passive or on-demand)

How to do it…

  1. Let's open a terminal window:
    $ cd $WILDFLY_HOME
    $ ./bin/jboss-cli.sh
    You are disconnected at the moment. Type connect to connect to the server or help for the list of supported commands.
    [disconnected /]
  2. Once in, we need to connect to the running instance. By typing the command connect, the tool connects to the instance with the default parameters, which is localhost:9990.
    [disconnected /] connect
    [standalone@localhost:9990 /]
  3. You can also connect to the CLI directly from the command line by passing the --connect parameter as follows:
    $ cd $WILDFLY_HOME
    $ ./bin/jboss-cli.sh --connect
    [standalone@localhost:9990 /]

    From now on, we will connect directly to the CLI without having to connect to it from the inside.

  4. Now try the command listing ls (as you would do in Linux):
  5. The list command gives you all the components that you can operate on, pretty much what you can see editing the standalone.xml. In fact, listing the subsystems, you will see all the subsystems present declared in standalone.xml:

There's more…

Remember that the Tab key on your keyboard is your friend. If you don't remember a command, just hit Tab. If you don't remember how to complete a command, just hit Tab. Hitting the Tab key will show all the possible solutions within your current context.

There are two others special characters within the CLI: / (the forward slash) and : (the colon). The forward slash is used to navigate through the contexts, while the colon is used to invoke method operation within the last selected context. Check the next recipe for an example.