Java jar Package Conflict resolution method

Source: Internet
Author: User

Jar packet collisions are almost always a problem for every Java programmer, and especially for large projects, jar packages are dependent on each other and frequent packet collisions occur. A few runtime exceptions are typically reported:

    • Java.lang.NoSuchMehodError
    • Java.lang.NoClassDefFoundError
This kind of problem is mostly caused by jar package conflict, to solve the jar package conflict problem, we first understand the cause of this conflict.
Causes of jar package conflicts

1, MVN transmission dependency characteristics: MVN compiled packaging will introduce a direct declaration of dependency, but also introduce the indirect declaration of dependency

2. MVN's reliance on arbitration rules:

1). Arbitration in accordance with the Dependencymanager version statement of the project general Control Pom.
2). If no arbitration declaration is made, the version is determined according to the shortest path dependent.
3). If the same path, a strict interval-limited version is preferred.
4). If the same path, no version range, then the preconceived principle.

3. The scope of dependency affects the extent of dependency.


Three ways to solve a simple conflict!

1. Depending on the class name or method name of the error to locate the jar package that might cause the conflict, there are several scenarios in which the jar package conflict is introduced:

1). The introduction of multiple versions of the jar package, while mvn the wrong version of the quorum, the version itself lacks the correct class or method.

2). The sequential differences between multiple JAR,MVN loading classes with different coordinates but with the same name can cause loading to the wrong class.

2. Export all dependencies through MVN dependency:tree > Tree.txt. You can use the-dverbose,-dincludes, or-dexcludes parameters to pinpoint the jar package that caused the conflict.

3. Find the dependent jar packages that need to be excluded, define the correct jar packages by MVN arbitration first, or exclude the wrong jar packages by exclusion.

4. Tips: In addition, in the project development jar as far as possible to introduce, system management, do not care about anything directly into the package, this can also reduce the risk of jar package conflict to a certain extent.


Java jar Package Conflict resolution method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.