Tag Archives: Java

Tell the time with online clock face test

Yet another homework-inspired addition to the API – a clock face image generator. My son brought home a worksheet from school with badly-drawn clock faces on it. On some clock faces the minute hand was pointing to the “6” (half-past) while the hour hand pointed directly at the 3, when it should have pointed either half way between 2-3 or half way between 3-4.

The clock-face image URL creates a random clock face if no arguments are present. Query arguments are ‘time’ to specify time in milliseconds since midnight. A ‘resolution’ argument controls the resolution of randomly-generated times and also to hide the seconds hand for anything greater than second. Values for ‘resolution’ are one of [second, minute, fives, quarter, half, hour]. The ‘width’ argument is a 3-digit size in pixels of the generated image.

A .json API URL returns some data useful for embedding the clock face as an interactive test:





What is the time?

Starting a class with One-JAR that’s not your Main-Class

I use One-JAR to package a number of .jars from different project into a single jar file which is my distributable application. Within that jar file are a multitude of utility classes. To run my application I use

java -jar myonejar.jar

which launches my application’s main class com.firtl.MainClass just fine. I’d also like to be able to run some utility classes from the same jar like this:

java -cp myonejar.jar com.firtl.UtilityClass input1.bin input2.bin

This doesn’t work because One-JAR produces a jar file for an application class com.simontuffs.onejar.Boot – your own application’s jar file ends up in a /lib ‘directory’ in the jar file. You need to tell the Boot class to load and execute your utility class. You can pass command-line ‘switches’ to the Boot class via the Java system property facility. One-JAR supports a few, some useful help text is available by:

java -jar myonejar.jar --one-jar-help

The system property you need to set is one-jar.main.class – make sure you set the property before -jar:

java -Done-jar.main.class=com.firtl.UtilityClass -jar myonejar.jar input1.bin input2.bin

One-JAR’s Boot class will load UtilityClass and pass {“input1.bin”, “input2.bin”} to its main method. Easy once you know how!