๐ŸŒ
Apache Commons
commons.apache.org โ€บ cli
Apache Commons CLI โ€“ Apache Commons CLI
November 8, 2025 - The Apache Commons CLI library provides an API for parsing command-line options passed to an application. It can also print help detailing the options available for that application ยท Commons CLI supports different types of options:
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ intro to the apache commons cli
Intro to the Apache Commons CLI | Baeldung
February 20, 2025 - Similar to the parse() method in the CommandLineParser class, the HelpFormatter also uses the Options Class to display the help text of a CLI tool. Letโ€™s explore more about the Apache Commons CLI library classes and understand how they help create a CLI tool consistently and quickly.
๐ŸŒ
DZone
dzone.com โ€บ coding โ€บ java โ€บ java command-line interfaces (part 1): apache commons cli
Java Command-Line Interfaces (Part 1): Apache Commons CLI
June 22, 2017 - The "Builder" pattern implemented for Apache Commons CLI as shown in the above example features the benefits of the builder pattern such as creating an Option in a fully completed state in one statement and use of highly readable builder methods to set that instance's various fields. My older post on Apache Commons CLI demonstrates the use of the alternate traditional constructor approach to instantiating Option instances. With the command-line options defined, it's time to move to the "parsing" stage and the next code listing demonstrates how to parse with Apache Commons CLI by simply invoking the method CommandLinePaser.parse().
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ commons_cli โ€บ commons_cli_quick_guide.htm
Apache Commons CLI - Quick Guide
Option object is used to represent the Option passed to command line program. Following are various properties that an Option object possess. Let's create a sample console based application, whose purpose is to get sum of passed numbers based on the option used. package com.tutorialspoint; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; public class CLITester { public static void main(
๐ŸŒ
GitHub
github.com โ€บ apache โ€บ commons-cli
GitHub - apache/commons-cli: Apache Commons CLI ยท GitHub
Apache Commons CLI provides a simple API for presenting, processing, and validating a Command Line Interface.
Starred by 391 users
Forked by 249 users
Languages ย  Java 97.4% | JavaScript 2.4%
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ linux-linux-apachectl-command-with-practical-examples-422544
Linux apachectl Command with Practical Examples | LabEx
Next, let's explore the different options available with the apachectl command: ... Usage: apachectl [option] Options: start Start the Apache httpd daemon stop Stop the Apache httpd daemon restart Restart the Apache httpd daemon graceful Gracefully ...
๐ŸŒ
Apache Commons
commons.apache.org โ€บ exec โ€บ commandline.html
Apache Commons Exec - Building the command line โ€“ Apache Commons Exec
No matter which approach you are using commons-exec does change your command line arguments in the following two cases ยท The following executable arguments
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ commons_cli โ€บ commons_cli_usage_example.htm
Apache Commons CLI - Usage Example
In this example, we're printing usage using HelpFormatter if no argument is passed. package com.tutorialspoint; import java.io.IOException; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.help.HelpFormatter; public class CLITester { public static void main(String[] args) throws ParseException, IOException { Options options = new Options(); options.addOption("p", "print", false, "Send print request to printer.") .addOption("g", "gui", false, "Show GUI Application") .addOption("n", true, "No.
๐ŸŒ
Linuxize
linuxize.com โ€บ home โ€บ apache โ€บ apache commands: manage and troubleshoot your web server
Apache Commands: Manage and Troubleshoot Your Web Server | Linuxize
April 8, 2026 - AH00526: Syntax error on line 12 of /etc/apache2/sites-enabled/example.conf: Invalid command 'SSLCertificateFil', perhaps misspelled or defined by a module not included in the server configuration
Find elsewhere
๐ŸŒ
TecMint
tecmint.com โ€บ home โ€บ web servers โ€บ apache โ€บ useful commands to manage apache web server in linux
Useful Commands to Manage Apache Web Server in Linux
May 10, 2019 - Usage: httpd [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|stop] [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X] Options: -D name : define a name for use in directives -d directory ...
Top answer
1 of 1
3

Here's a very stripped down version of something I use. It basically sets up a singleton that gets initialized once and then can be used wherever you want within your program. I chose to store the info in HashMap's and ArrayList's because they were easier to deal with later.

//****************************************************************************
//***** File Name: MianCLIOptions.java
//****************************************************************************

package com.test.mian;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.cli.AlreadySelectedException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.MissingArgumentException;
import org.apache.commons.cli.MissingOptionException;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.UnrecognizedOptionException;
import org.apache.commons.lang.WordUtils;


//****************************************************************************
//****************************************************************************
//****************************************************************************
//****************************************************************************
public class MianCLIOptions
{
    //***** constants *****

    //***** public data members *****

    //***** private data members *****
    private static MianCLIOptions singletonObj = null;

    private HashMap<String,Object> options = new HashMap<String,Object>();
    private ArrayList<String> arguments = new ArrayList<String>();

    //****************************************************************************
    public static MianCLIOptions getopts()
    {
        if (singletonObj == null) {
            throw new IllegalStateException("[MianCLIOptions] Command line not yet initialized.");
        }

        return singletonObj;
    }

    //****************************************************************************
    public static synchronized void initialize(Options optsdef, String[] args)
        throws MianCLIOptionsException, UnrecognizedOptionException, MissingArgumentException,
               MissingOptionException, AlreadySelectedException, ParseException
    {
        if (singletonObj == null) {
            singletonObj = new MianCLIOptions(optsdef, args);
        }
        else {
            throw new IllegalStateException("[MianCLIOptions] Command line already initialized.");
        }
    }

    //****************************************************************************
    //----- prevent cloning -----
    public Object clone() throws CloneNotSupportedException
    {
        throw new CloneNotSupportedException();
    }

    //****************************************************************************
    public boolean isset(String opt)
    {
        return options.containsKey(opt);
    }

    //****************************************************************************
    public Object getopt(String opt)
    {
        Object rc = null;

        if (options.containsKey(opt)) {
            rc = options.get(opt);
        }

        return rc;
    }

    //****************************************************************************
    //***** finally parse the command line
    //****************************************************************************
    private MianCLIOptions(Options optsdef, String[] args)
        throws UnrecognizedOptionException, MissingArgumentException,
               MissingOptionException, AlreadySelectedException, ParseException
    {
        //***** (blindly) parse the command line *****
        CommandLineParser parser = new GnuParser();
        CommandLine cmdline = parser.parse(optsdef, args);

        //***** store options and arguments *****
        //----- options -----
        for (Option opt : cmdline.getOptions()) {
            String key = opt.getOpt();
            if (opt.hasArgs()) {
                options.put(key, opt.getValuesList());
            }
            else {
                options.put(key, opt.getValue());
            }
        }

        //----- arguments -----
        for (String str : cmdline.getArgs()) {
            //----- account for ant/build.xml/generic -----
            if (str.length() > 0) {
                arguments.add(str);
            }
        }
    }
}

//****************************************************************************
//***** EOF  ***** EOF  ***** EOF  ***** EOF  ***** EOF  ***** EOF  **********

In your main, you can then call it like so:

    //***** build up options *****
    Options options = new Options();

    // ... .... ...

    //***** process command line *****
    try {
        MianCLIOptions.initialize(options, args);
    }
    catch (UnrecognizedOptionException ex) {
        // do something
    }

And finally, in some other class you can call it like so:

    MianCLIOptions opts = MianCLIOptions.getopts();
    if (opts.isset("someopt")) {
        // do something exciting
    }

Hope that helps!

๐ŸŒ
GitHub
gist.github.com โ€บ jagwarthegreat โ€บ aae54e22b3b4eae4d217276c78099abe
APACHE2 COMMANDS ยท GitHub
## Start command ## systemctl start apache2.service ## Stop command ## systemctl stop apache2.service ## Restart command ## systemctl restart apache2.service
๐ŸŒ
Java Code Geeks
javacodegeeks.com โ€บ home โ€บ core java
Java Command-Line Interfaces (Part 1): Apache Commons CLI - Java Code Geeks
July 21, 2017 - Example of Using Apache Commons CLI Option.Builder for โ€œDefinition Stage ยท /** * "Definition" stage of command-line parsing with Apache Commons CLI. * @return Definition of command-line options.
๐ŸŒ
2DayGeek
2daygeek.com โ€บ home โ€บ cheatsheet for apache2 commands
Cheatsheet For Apache2 Commands | 2DayGeek
May 4, 2020 - $ apache2ctl -S or $ apachectl -S VirtualHost configuration: *:80 node3.2g.lab (/etc/apache2/sites-enabled/000-default.conf:1) ServerRoot: "/etc/apache2" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/var/log/apache2/error.log" Mutex watchdog-callback: using_defaults Mutex default: ...
๐ŸŒ
TecAdmin
tecadmin.net โ€บ common-apache-commands-on-ubuntu-debian
Common Apache Commands on Ubuntu & Debian โ€“ TecAdmin
April 26, 2025 - Use a2enmod command to enable a module in Apache server and a2dismod to disable the module. For example to enable rewrite module, type: ... The latest operating systems have opted the system for managing services.
๐ŸŒ
Apothem
apothem.blog โ€บ apache-commons-cli.html
Apache Commons CLI | APOTHEM
August 31, 2020 - the short version of the option as a parameter of the builder method (v in this example), so that we can use it as -v on the command line);
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ commons_cli โ€บ index.htm
Apache Commons CLI Tutorial
This tutorial is tailored for readers who aim to understand and utilize Apache Commons CLI utilities. In this tutorial, we'll cover all the ways of using Apache Common CLI which helps in solving the common problems developers/users face during development while dealing with Command Line based development.
๐ŸŒ
DevDojo
devdojo.com โ€บ post โ€บ serverenthusiast โ€บ 14-apache-commands-to-help-you-manage-your-server-like-a-pro
14 Apache commands to help you manage your server like a pro - DevDojo
August 19, 2020 - I aim to always run this command before restarting Apache, that way I am sure that Apache will start if the syntax is OK. Output in case that there are no problems with your configuration file: ... Output in case that you've made a mistake or if there are any issues with your Apache configuration: AH00526: Syntax error on line 1 of /etc/apache2/sites-enabled/000-default.conf: Invalid command 'load_module', perhaps misspelled or defined by a module not included in the server configuration Action '-t' failed.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ linux-unix โ€บ most-useful-commands-to-manage-apache-web-server-in-linux
Most Useful Commands to Manage Apache Web Server in Linux - GeeksforGeeks
July 23, 2025 - For checking Apache configuration files for finding any syntax errors on Debian-based systems before restarting the service use the following command:- ... All the virtual hosts on the server, their options, and the file names and line numbers that they define, an error message with the line ...
๐ŸŒ
Java Code Geeks
javacodegeeks.com โ€บ home โ€บ core java
Intro to the Apache Commons CLI - Java Code Geeks
May 24, 2024 - If an exception occurs during parsing (such as invalid command-line arguments), a ParseException is caught, and a HelpFormatter instance is used to print the help message, which provides information about how to use the CLI application with the available options. These examples demonstrate the flexibility and power of the Apache ...