Monday 22 November 2010

Strange errors while using maven (dependency mess)

(Java&Maven)


I have two projects built with maven. One of them includes the other.
The new requirement that I have done is working in the original (common) project, but, even the simplest call to this functionality from the upper project results with an error (in current case with ClassNotFoundException, but this can be any time of error).

Here is one of the thing that should be done when you don't have the clue - check dependencies. By using maven it is possible to have a mess with them if you do not use exclusions within dependency tags. This way you can get two versions of the same JAR downloaded, and the older version used - so you got the class not found exception.

Useful tool is within Eclipse Galileo: open pom.xml and check all items within Dependency Hierarchy. From there you can build a list with duplicated and conflicted versions of JARs, and a list of exclusions you need to set in same pom.xml file.
After altering pom.xml file, check the hierarchy again - you should have one position in the hierarchy for each resolved dependency (or at least positions within same library in the hierarchy without any conflicts).

No comments:

Popular Posts