What am I missing here? Using cronutils.jar

I’m trying to parse Linux cron schedules in Lucee using the com.cronutils jar.
Here’s my code:

<!--- Load the required classes --->
<cfset CronDefinitionBuilder = createObject("java", "com.cronutils.model.definition.CronDefinitionBuilder") />
<cfset CronType = createObject("java", "com.cronutils.model.CronType") />
<cfset CronParser = createObject("java", "com.cronutils.parser.CronParser") />

<!--- Create a CronParser instance --->
<cfset cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX) />
<cfset parser = CronParser.init(cronDefinition) />

<!--- Parse the cron expression --->
<cfset cron = parser.parse("5 * * * *") />
<cfoutput>#cron#</cfoutput>

What gets output is “com.cronutils.model.SingleCron@5ff9f056”
I’m expecting to see something like “Every 5 minutes”

What am I doing wrong here?
Here are the cronutils docs for reference:
https://javadoc.io/doc/com.cronutils/cron-utils/latest/index.html

TIA

PS - Lucee 5.4.6.9, Tomcat 9, Windows

1 Like

Everything’s cool. I was just doing it wrong. I needed to use the CronDescriptor object to get the value I was looking for. What I previously created was a Cron object – something different.

Here’s a complete working example:

function parseCron(required string cronStr) {
	var CronDefinitionBuilder = createObject("java", "com.cronutils.model.definition.CronDefinitionBuilder");
	var CronType = createObject("java", "com.cronutils.model.CronType");
	var CronParser = createObject("java", "com.cronutils.parser.CronParser");
	var CronDescriptor = createObject("java", "com.cronutils.descriptor.CronDescriptor");
	var Locale = createObject("java", "java.util.Locale");
	var Descriptor = CronDescriptor.instance(Locale.ENGLISH);
	var cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
	var parser = CronParser.init(cronDefinition);
	var cron = parser.parse(cronStr);
	return Descriptor.describe(cron);

}
echo(parseCron("18 0 * * *"));
2 Likes