Maven: several classes with the same path implemented in different banks

I am having problems with having multiple classes with the same path (i.e. with the same name, same package !!!). For some reason, gwt-dev has 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 on different cans. I don't know what it should be, but it looks like xalan and xml-api - these are two dependencies that spring depends on (this dependency is optional)

It's funny that eclipse can run the same code (this is unit test) without problems, but surefire cannot. Therefore, I assume that the problem is related to how each runner considers the priority of each bank.

Now let's move on to the question: how to configure my POM so that I can make sure that someday some code works inside my application, then the class from jar will be selected from the class from another jar?

Thanks.

+4
source share
3 answers

Now let's move on to the question: how to configure my POM so that I can make sure that someday some code works inside my application, then the class from jar will be selected from the class from another jar?

Since Maven 2.0.9, Maven uses the dependency order in the POM to create a class path so that you can manipulate it. Just first declare the “correct” jar, and your application will select a class from it.

From the maven 2.0.9 release notes:

MNG-1412 / MNG-3111 introduced deterministic ordering of class path dependencies. Previously, natural ordering was used, which led to odd results. Now the order is saved from your pom, and the dependencies are added by the last addition. In assemblies with conflicting or duplicate dependencies, this can lead to a change in output. In short, if you have strange problems with 2.0.9, look at the dependencies to see if you have conflicts somewhere.

+11
source

Dependencies within maven projects can be a problem for troubleshooting. what do i usually do ...

  • mvn dependency: tree in your project to find out who is dependent on the classes that are causing the problems.
  • try excluding classes that you think are causing the problem by editing your pom.xml.

hope this helps!

0
source

To find out which jar is causing the problems: run Maven with the -X flag.

To configure POM to exclude corresponding banks (s):

 <yourproject.deployment.excludes> artifactId1,artifactId2,... </yourproject.deployment.excludes> 

...

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${your.lib.for.example}</outputDirectory> <overWriteSnapshots>true</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> <excludeTransitive>false</excludeTransitive> <excludeArtifactIds>${yourproject.deployment.excludes}</excludeArtifactIds> <includeScope>compile</includeScope> </configuration> </execution> </executions> </plugin> 
0
source

Source: https://habr.com/ru/post/1306548/


All Articles