11package sample .java .project ;
22
3- import org .apache .commons .cli .Option ;
4- import org .apache .commons .cli .Options ;
5- import org .apache .commons .cli .GnuParser ;
3+ import java .util .Timer ;
4+ import java .util .TimerTask ;
65import org .apache .commons .cli .CommandLine ;
6+ import org .apache .commons .cli .GnuParser ;
77import org .apache .commons .cli .HelpFormatter ;
8+ import org .apache .commons .cli .Option ;
9+ import org .apache .commons .cli .Options ;
810
911/**
1012 * The main class.
1113 *
1214 * This is the main class of the application. It contains the main()
1315 * method, the first method called.
1416 */
15- public class SampleJavaProject {
17+ public class SampleJavaProject extends TimerTask {
18+
19+ /** The delay between printed messages. */
20+ private static final long PRINT_DELAY = 1000L ;
1621
1722 /** The name to printed in the output message. */
1823 private static String name = "world" ;
@@ -28,6 +33,7 @@ public static void main(final String[] args) {
2833 /* Set up the command line arguments. */
2934 Options options = new Options ();
3035 options .addOption (new Option ("name" , true , "set the user's name" ));
36+ options .addOption (new Option ("loop" , "print endlessly, hotswap demo" ));
3137 options .addOption (new Option ("help" , "print this help message" ));
3238 CommandLine line = null ;
3339 try {
@@ -46,8 +52,15 @@ public static void main(final String[] args) {
4652 if (line .hasOption ("name" )) {
4753 name = line .getOptionValue ("name" );
4854 }
55+ if (line .hasOption ("loop" )) {
56+ new Timer ().schedule (new SampleJavaProject (), 0L , PRINT_DELAY );
57+ } else {
58+ new SampleJavaProject ().run ();
59+ }
60+ }
4961
50- /* Print out our message. */
62+ @ Override
63+ public final void run () {
5164 System .out .printf ("Hello, %s!\n " , name );
5265 }
5366
0 commit comments