Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: Multiple class with the same path implemented in different jar

I'm running into trouble with having multiple class with the same path (i.e. same name, same package!!!). For some reason, gwt-dev comes with its own version of org.apache.xerces.jaxp.DocumentBuilderFactoryImpl and javax.xml.parsers.DocumentBuilderFactory.

At the same time, spring also depends on these classes but from different jar. I don't know what should be, but look like xalan & xml-api are the two dependencies that spring depends on (these dependency are optional)

Funny thing is that eclipse can run the same code (it's a unit test) without problem, but surefire cannot. So I guess the problem is due to the way each runner consider the priority of each jar.

Now come to the question: How can I setup my POM so that I can sure that when ever any code running inside my app, then class from a jar will be selected over class from other jar?

Thanks.

like image 658
Phương Nguyễn Avatar asked Apr 10 '10 08:04

Phương Nguyễn


1 Answers

Now come to the question: How can I setup my POM so that I can sure that when ever any code running inside my app, then class from a jar will be selected over class from other jar?

Since Maven 2.0.9, Maven uses the order of dependencies in the POM to build the classpath so you can manipulate it. Just declare the "right" jar first and your app will pick the class from it.

From the release notes of maven 2.0.9:

MNG-1412 / MNG-3111 introduced deterministic ordering of dependencies on the classpath. In the past, natural set ordering was used and this lead to odd results. The ordering is now preserved from your pom, with dependencies added by inheritence added last. In builds that had conflicting or duplicate dependencies, this may introduce a change to the output. In short, if you have weird issues with 2.0.9, take a look at the dependencies to see if you have conflicts somewhere.

like image 103
Pascal Thivent Avatar answered Jan 02 '23 20:01

Pascal Thivent