maven多继承关系

在 Maven 中对于继承采用的也是单一继承,也就是说一个子项目只能有一 个父项目,但是有的时候我们项目可能需要从更多的项目中继承,那么我们可以 在子项目中通过添加<dependencyManagement>标记来实现多继承。在子项 目的<dependencyManagement>中每个<dependency>标记就一个父工程 定义,同时还需要添加<type>标记,值为 pom。添加<scope>标记,值为 import。 1.多继承方法一

maven多继承关系

点击查看代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!--    继承父类的坐标 父项目 A-->
    <parent>
        <groupId>com.bjsxt</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.bisxt</groupId>
    <artifactId>child</artifactId>
    <version>1.0-SNAPSHOT</version>
<!--    通过dependencyManagement标签添加父类-->
    <dependencyManagement>
        <dependencies>
<!--            父项目B-->
            <dependency>
                <groupId>com.bisxt</groupId>
                <artifactId>parent_b</artifactId>
                <version>1.0-SNAPSHOT</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
    </dependencies>

</project>

2.多继承二
maven多继承关系

点击查看代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!--    继承父类的坐标 父项目 A-->
<!--    <parent>-->
<!--        <groupId>com.bjsxt</groupId>-->
<!--        <artifactId>parent</artifactId>-->
<!--        <version>1.0-SNAPSHOT</version>-->
<!--    </parent>-->
    <groupId>com.bisxt</groupId>
    <artifactId>child</artifactId>
    <version>1.0-SNAPSHOT</version>
<!--    通过dependencyManagement标签添加父类-->
    <dependencyManagement>
        <dependencies>
<!--            父项目B-->
            <dependency>
                <groupId>com.bisxt</groupId>
                <artifactId>parent_b</artifactId>
                <version>1.0-SNAPSHOT</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.bjsxt</groupId>
                <artifactId>parent</artifactId>
                <version>1.0-SNAPSHOT</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
    </dependencies>

</project>
上一篇:CentOS7启动图形界面


下一篇:SQL Plan Management介绍