Over a million developers have joined DZone.

Command-line Parsing In Java

·

/**
 * This will print the message “Hello World” on the console. The additional
 * functionality is that you can control the case of the message. 
 * The default will be mixed case. A command-line argument
 * can force the message to upper case. This argument is --upperCase.
 */
public class HelloWorld {  
  
    public boolean asUpperCase;  
  
    static public int main (String[] args) {  
  
       CmdLine.create("-t boolean -k upperCase --variable asUpperCase")  
            .parse(this, args);  
  
       if (asUpperCase)  
          System.out.println("Hello World".toUpperCase());  
       else  
          System.out.println("Hello World");  
    }  
}


see Little Gray Cloud's command-line utility for the JAR file.

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}