Quartz error @daily and other shortcuts
Unexpected character: @
java.lang.RuntimeException: CronExpression '@daily' is invalid.
Caused by: java.text.ParseException: Unexpected character: @Message produced by running the expression through org.quartz.CronExpression from Quartz 2.5.2.
What it means
Shortcuts like @daily, @hourly and @weekly come from Unix cron. Quartz has none of them, so the @ is the first thing it can’t read. Write the fields out instead.
Rejected expressions and their fixes
Each expression opens in the tester. The message under a rejected one is what Quartz 2.5.2 printed for it.
-
Use0 0 * * * ?Every hour, on the hour.
On the hour, every hour.
-
Use0 0 0 * * ?At 00:00.
Midnight every day.
-
Use0 0 0 ? * SUNAt 00:00, on Sundays.
Midnight at the start of Sunday, as cron’s
@weeklyis. -
Use0 0 0 1 * ?At 00:00, on the 1st of the month.
Midnight on the 1st.
-
Use0 0 0 1 1 ?At 00:00, on the 1st of the month, in January.
Midnight on 1 January.
Questions
- What is
@dailyin Quartz? 0 0 0 * * ?: second 0, minute 0, hour 0, every day of the month, with day of week left as?.- Does Kubernetes accept
@daily? - Yes. The parser behind Kubernetes CronJobs accepts
@yearly,@monthly,@weekly,@dailyand@hourly. Quartz, EventBridge, GitHub Actions and Azure do not.
Other Quartz errors
- Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.Quartz: Both day fields are set
- Unexpected end of expression.Quartz: Five fields instead of six
- '?' can only be specified for Day-of-Month -OR- Day-of-Week.Quartz:
?in the wrong place - Day-of-Week values must be between 1 and 7Quartz: Sunday written as 0
- Hour values must be between 0 and 23Quartz: A value out of range
- Increment >= 60 : 90Quartz: A step longer than the field