Skip to content

Commit e71924f

Browse files
committed
Add --loop option for better hotswap demoing.
1 parent 4f79a5f commit e71924f

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
dist
33
lib
4+
cache.properties

build.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
description="Run the application in hotswap mode.">
7373
<java jar="${dist.dir}/${jar.file}" fork="true">
7474
<jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,address=9000,server=y,suspend=n"/>
75+
<arg value="--loop"/>
76+
<arg value="--name"/>
77+
<arg value="Java"/>
7578
</java>
7679
</target>
7780

src/sample/java/project/SampleJavaProject.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package 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;
65
import org.apache.commons.cli.CommandLine;
6+
import org.apache.commons.cli.GnuParser;
77
import 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

Comments
 (0)