Ramarao
Ramarao

Reputation: 3

Loading a class from single jar among several jars

I want to you use a class 'javax.xml.stream.XMLOutputFactory' in code. The class (XMLOutputFactory) is available in more than one jars of library which got included as maven dependencies. Problem : The class(XMLOutputFactory) is loading from the jar file while i am expecting to load from other jar. Is there any solution to customize the loading of a class from the specific jar file.

Upvotes: 0

Views: 64

Answers (2)

ben75
ben75

Reputation: 28706

Since maven 2.0.9 the classpath is generated according dependencies declaration in pom.xml.

From maven site:

Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins.

So you can solve your problem if you take care of dependencies ordering in your pom.xml

Upvotes: 1

pgras
pgras

Reputation: 12770

Not on the java side (or maybe by implementing a new classloader but that is not a reasonable solution to your problem).

You should probably just exclude the dependencies (versions) you don't want in your pom file.

Upvotes: 2

Related Questions