Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#.Arg' - 1 code snippet(s) found

 Sample 1. Using kohsuke for command line options

Add the following dependency

<dependency>
      <groupId>org.kohsuke.args4j</groupId>
      <artifactId>args4j-maven-plugin</artifactId>
      <version>2.33</version>
</dependency>

In the main class add the following element

@Option(name = "-date", required = true, metaVar = "mmddyyyy", usage = "date for which we want this to happen")
private String date = null;

Within the main method add code to parse command line args and populate date

public static void main(String args[]){
try {
    parser.parseArgument(args);
    SimpleDateFormat commandLineDateFormat = new SimpleDateFormat("mmddyyyy", Locale.getDefault());
Date date = commandLineDateFormat.parse(date);

    } catch (Exception ex){
       ex.printStackTrace();
    }
}

   Like      Feedback     org.kohsuke.args4j.CmdLineParser  org.kohsuke.args4j.Option   kohsuke  command line options



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner