Wednesday, May 27, 2009

Maven, Quartz and Spring 2.x

If you have tried to use scheduling in Spring 2.x and you are using Maven - you will probably be having trouble.

In your stacktrace, you might be seeing this:

Caused by: java.lang.NoClassDefFoundError: org/quartz/ObjectAlreadyExistsException
at java.lang.Class.getDeclaredConstructors0(Native Method)

or this:

Caused by: java.lang.NoSuchMethodError: org.apache.commons.collections.SetUtils.orderedSet(Ljava/util/Set;)Ljava/util/Set;
at org.quartz.JobDetail.(JobDetail.java:85)


It seems that the good folks over at OpenSymphony (makers of Quartz) couldn't care less about Maven (I don't blame them) and making sure their pom.xml is correct (which it isn't).

And Spring, which uses Quartz for scheduling, doesn't seem too concerned either about making sure that their pom.xml has the correct dependencies for Quartz (which it doesn't).

The short of it is, if you want everything to just work, you'll need to explicitly include these two dependencies in your pom.xml:

        <dependency>
<groupid>opensymphony</groupid>
<artifactid>quartz-all</artifactid>
<version>1.6.1</version>
</dependency>
<dependency>
<groupid>commons-collections</groupid>
<artifactid>commons-collections</artifactid>
<version>3.2</version>
</dependency>


And so, if you are in the unfortunate position of having to use Maven, I empathise. Let us weep together.

2 comments:

tim said...

Thanks for the post... saved me some time debugging :)

Anonymous said...

That's very helpful. Thanks a million.

One little point to note. Those tag with "id" should be written in "Id", such as "groupid" should be written as "groupId". I'm not sure whether that's only the problem at my side.