Home > Java > javaTutorial > body text

Introduction to the method of setting the priority of dependent packages

不言
Release: 2019-02-13 15:39:29
forward
4122 people have browsed it

This article brings you an introduction to the priority setting method of dependent packages. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The problem arises: the refund function of an old project was disabled by the WeChat payment backend because the xml parsing tool has vulnerability risks.
The solution given by WeChat customer service is to use the official patch.
After using the patch, it was found that the xml-api package conflicts with the package that comes with jdk.
Specific reasons:
A certain class in the xml-api package has the same fully qualified name as a class that comes with jdk, but there is no relevant implementation in the xml-api package.
The IDE does not depend on jdk The built-in package instead relies on the xml-api package first, causing the project to fail to complete compilation.

Try to solve:
在 Maven 中排除 xml-api 包:
    从父 pom 里面做排除:
        但是项目年代久远,各种类库的依赖盘根错节,
        到父 pom 里面没找到依赖,到依赖的自定义基本库里面也没找到。
        况且考虑到父 pom 被其他项目依赖的可能性,所以还是想想其他办法。
    全局排除:
        在 pom 文件里加入冲突包的依赖,然后再排除包里全部的内容:
            <dependency>
                <groupId></groupId>
                <artifactId></artifactId>
                <version></version>
                <exclusions>
                    <exclusion>
                        <groupId>*</groupId>
                        <artifactId>*</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        这个方法能够排除掉项目对 xml-api 包里的全部依赖;
            但是因为先导入后排除,项目依然会优先依赖 xml-api 包;所以问题还是没有解决。
Copy after login
Recommended solution:
修改依赖包的优先级:

    因为这个老项目是用 Eclipse 开发,先说 Eclipse 操作方法。
    Eclipse:
        设置 build path order;
        把优先级高的包放到上面,
        所以可以把 jre 的包放到最上面。
    
    顺便看了下 IDEA 的设置,也能修改优先级。
    IDEA:
        修改 classpath order:
        菜单:File -> Project Structure -> Modules
        快捷键:Ctrl + Alt + Shift + S  -> Modules
        把优先级高的包放到上面,
        IDEA 中,jdk 自带的包默认就是最高优先级,所以使用 IDEA 不会出现类似的问题。
Copy after login


The above is the detailed content of Introduction to the method of setting the priority of dependent packages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template