论坛首页 综合技术论坛

maven_聚合和继承

浏览 2240 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-04-14  
聚合主要是为了解决多个模块一起构建。也就是说在上面的用户项目中,多个模块统一在一个额外的模块来构建整个项目的所有模块。

继承主要是为了解决多个模块重复配置的问题。

下面来看看怎样来修改用户小项目

首选建一个额外模块user-parent,这个模块主要用一个pom.xml文件即可。配置如下:
<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>  
  
    <groupId>com.naxsu.user</groupId>  
    <artifactId>user-parent</artifactId>  
    <version>0.0.1-SNAPSHOT</version>  
    <!-- packaging的类型为pom -->  
    <packaging>pom</packaging>  
  
    <!-- module的值是一个以当前POM为主目录的相对路径 -->  
    <modules>  
        <module>../user-core</module>  
        <module>../user-dao</module>  
        <module>../user-log</module>  
        <module>../user-service</module>  
    </modules>  
  
    <url>http://maven.apache.org</url>  
  
    <properties>  
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
        <junit.version>4.10</junit.version>  
    </properties>  
  
    <dependencyManagement>  
        <dependencies>  
            <dependency>  
                <groupId>junit</groupId>  
                <artifactId>junit</artifactId>  
                <version>${junit.version}</version>  
                <scope>test</scope>  
            </dependency>  
  
            <dependency>  
                <groupId>com.naxsu.user</groupId>  
                <artifactId>user-core</artifactId>  
                <version>0.0.1-SNAPSHOT</version>  
            </dependency>  
  
            <dependency>  
                <groupId>com.naxsu.user</groupId>  
                <artifactId>user-dao</artifactId>  
                <version>0.0.1-SNAPSHOT</version>  
                <type>jar</type>  
                <scope>compile</scope>  
            </dependency>  
  
            <dependency>  
                <groupId>com.naxsu.user</groupId>  
                <artifactId>user-log</artifactId>  
                <version>0.0.1-SNAPSHOT</version>  
                <type>jar</type>  
                <scope>compile</scope>  
                <exclusions>  
                    <exclusion>  
                        <groupId>log4j</groupId>  
                        <artifactId>log4j</artifactId>  
                    </exclusion>  
                </exclusions>  
            </dependency>  
  
            <dependency>  
                <groupId>org.hibernate</groupId>  
                <artifactId>hibernate-core</artifactId>  
                <version>3.6.10.Final</version>  
            </dependency>  
  
            <dependency>  
                <groupId>log4j</groupId>  
                <artifactId>log4j</artifactId>  
                <version>1.2.16</version>  
            </dependency>  
  
            <dependency>  
                <groupId>mysql</groupId>  
                <artifactId>mysql-connector-java</artifactId>  
                <version>5.1.18</version>  
            </dependency>  
  
            <dependency>  
                <groupId>org.slf4j</groupId>  
                <artifactId>slf4j-log4j12</artifactId>  
                <version>1.6.4</version>  
            </dependency>  
  
            <dependency>  
                <groupId>javassist</groupId>  
                <artifactId>javassist</artifactId>  
                <version>3.12.1.GA</version>  
            </dependency>  
  
            <dependency>  
                <groupId>commons-logging</groupId>  
                <artifactId>commons-logging</artifactId>  
                <version>1.1.1</version>  
            </dependency>  
        </dependencies>  
    </dependencyManagement>  
</project>  


core模块的pom.xml文件修改如下:
<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>  
  
    <parent>  
        <groupId>com.naxsu.user</groupId>  
        <artifactId>user-parent</artifactId>  
        <version>0.0.1-SNAPSHOT</version>  
        <relativePath>../user-parent/pom.xml</relativePath>  
    </parent>  
  
    <artifactId>user-core</artifactId>  
    <name>user-core</name>  
  
    <dependencies>  
        <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>org.hibernate</groupId>  
            <artifactId>hibernate-core</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>log4j</groupId>  
            <artifactId>log4j</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>mysql</groupId>  
            <artifactId>mysql-connector-java</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>org.slf4j</groupId>  
            <artifactId>slf4j-log4j12</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>javassist</groupId>  
            <artifactId>javassist</artifactId>  
        </dependency>  
  
    </dependencies>  
</project>  


log模块的pom.xml文件修改如下:
<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>  
  
    <parent>  
        <groupId>com.naxsu.user</groupId>  
        <artifactId>user-parent</artifactId>  
        <version>0.0.1-SNAPSHOT</version>  
        <relativePath>../user-parent/pom.xml</relativePath>  
    </parent>  
  
    <artifactId>user-log</artifactId>  
    <name>user-log</name>  
  
    <dependencies>  
        <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>log4j</groupId>  
            <artifactId>log4j</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>commons-logging</groupId>  
            <artifactId>commons-logging</artifactId>  
        </dependency>  
    </dependencies>  
</project>  


dao模块的pom.xml文件修改如下:
<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>  
  
    <parent>  
        <groupId>com.naxsu.user</groupId>  
        <artifactId>user-parent</artifactId>  
        <version>0.0.1-SNAPSHOT</version>  
        <relativePath>../user-parent/pom.xml</relativePath>  
    </parent>  
  
    <artifactId>user-dao</artifactId>  
    <name>user-dao</name>  
  
    <dependencies>  
        <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>com.naxsu.user</groupId>  
            <artifactId>user-core</artifactId>  
        </dependency>  
  
    </dependencies>  
</project>  


service模块的pom.xml文件修改如下:
<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>  
    <parent>  
        <groupId>com.naxsu.user</groupId>  
        <artifactId>user-parent</artifactId>  
        <version>0.0.1-SNAPSHOT</version>  
        <relativePath>../user-parent/pom.xml</relativePath>  
    </parent>  
  
    <artifactId>user-service</artifactId>  
  
    <dependencies>  
        <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>com.naxsu.user</groupId>  
            <artifactId>user-dao</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>com.naxsu.user</groupId>  
            <artifactId>user-log</artifactId>  
        </dependency>  
    </dependencies>  
</project>  


本文链接:http://www.naxsu.com/maven_-ju-he-he-ji-cheng/
   发表时间:2012-04-14  
最近心情很不爽,找一下原因,原来我太在意别人的看法
0 请登录后投票
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics