DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Chris has posted 1 posts at DZone. View Full User Profile

Command-line Parsing In Java

  • submit to reddit
 * 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());  
          System.out.println("Hello World");  

see Little Gray Cloud's <a href="">command-line</a> utility for the JAR file.