zoukankan      html  css  js  c++  java
  • Maven学习总结(12)——eclipse中构建多模块maven项目

    摘要:本文要用Maven来构建一个多模块的web项目

    项目结构如下:

      system-parent
            |----pom.xml
            |----system-domain
                    |----pom.xml
            |----system-dao
                    |----pom.xml
            |----system-service
                    |----pom.xml
            |----system-web
                    |----pom.xml


    一、创建system-parent项目

      创建system-parent,用来给各个子模块继承

    勾选create a simple...

    注意要选pom

    创建好的结构如下,把src文件删除掉

    二、创建sytem-domain模块

    项目右键-》new->other

    注意选择maven module

    packageing,选择jar,因为这是要打包成jar给别的模块用的

    子模块添加好后如下


    打开system-domain项目pom.xml文件,改成如下

    [html] view plaincopy
    1. <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">  
    2.   <modelVersion>4.0.0</modelVersion>  
    3.     <parent>  
    4.         <groupId>com.mucfc</groupId>  
    5.         <artifactId>system-parent</artifactId>  
    6.         <version>0.0.1-SNAPSHOT</version>  
    7.     </parent>  
    8.       
    9.     <artifactId>system-domain</artifactId>  
    10.     <packaging>jar</packaging>  
    11.       
    12.     <name>system-domain</name>  
    13.     <url>http://maven.apache.org</url>  
    14. </project>  
    此时system-parent应该有这么一句

    [html] view plaincopy
    1. <modules>  
    2.     <module>system-domain</module>  
    3. </modules>  

    表明子模块添加成功

    三、创建system-dao模块

    步骤和2一样,命名不同


    然后把再打开system-dao的项目下的pom文件,修改成如下:

    [html] view plaincopy
    1. <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">  
    2.   <modelVersion>4.0.0</modelVersion>  
    3.     <parent>  
    4.         <groupId>com.mucfc</groupId>  
    5.         <artifactId>system-parent</artifactId>  
    6.         <version>0.0.1-SNAPSHOT</version>  
    7.     </parent>  
    8.     <artifactId>system-dao</artifactId>  
    9.     <packaging>jar</packaging>  
    10.   
    11.     <name>system-dao</name>  
    12.     <url>http://maven.apache.org</url>  
    13.     <dependencies>  
    14.     <!--system-dao需要使用到system-domain中的类,所以需要添加对system-domain模块的依赖-->  
    15.     <dependency>  
    16.         <groupId>com.mucfc</groupId>  
    17.         <artifactId>system-domain</artifactId>  
    18.          <version>${project.version}</version>  
    19.     </dependency>  
    20.  </dependencies>  
    21. </project>  

    四、创建system-service模块

    步骤和2一样,命名不同

    然后把再打开system-service的项目下的pom文件,修改成如下:

    [html] view plaincopy
    1. <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">  
    2.   <modelVersion>4.0.0</modelVersion>  
    3.     <parent>  
    4.         <groupId>com.mucfc</groupId>  
    5.         <artifactId>system-parent</artifactId>  
    6.         <version>0.0.1-SNAPSHOT</version>  
    7.     </parent>  
    8.       
    9.     <artifactId>system-service</artifactId>  
    10.     <packaging>jar</packaging>  
    11.   
    12.     <name>system-service</name>  
    13.     <url>http://maven.apache.org</url>  
    14.   
    15.     <dependencies>  
    16.         <!--system-service依赖system-dao和system-domain但是我们只需添加system-dao的依赖即可,因为system-dao已经依赖了system-domain -->  
    17.         <dependency>  
    18.             <groupId>com.mucfc</groupId>  
    19.             <artifactId>system-dao</artifactId>  
    20.             <version>${project.version}</version>  
    21.         </dependency>  
    22.     </dependencies>  
    23. </project>  

    五、创建system-web模块

    web项目要打包成war文件,所以有个地方要改下

    这里记得要选war文件

    把pom文件改成如下:

    [html] view plaincopy
    1. <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">  
    2.   <modelVersion>4.0.0</modelVersion>  
    3.     <parent>  
    4.         <groupId>com.mucfc</groupId>  
    5.         <artifactId>system-parent</artifactId>  
    6.         <version>0.0.1-SNAPSHOT</version>  
    7.     </parent>  
    8.       
    9.     <artifactId>system-web</artifactId>  
    10.     <packaging>war</packaging>  
    11.   
    12.     <name>system-web</name>  
    13.     <url>http://maven.apache.org</url>  
    14.   
    15.     <dependencies>  
    16.         <dependency>  
    17.             <groupId>com.mucfc</groupId>  
    18.             <artifactId>system-service</artifactId>  
    19.             <version>${project.version}</version>  
    20.         </dependency>  
    21.     </dependencies>  
    22. </project>  
    然后自己在在system-websrcmainwebapp目录中添加一个index.jsp

    六、整体目录如下
                                                                                          

  • 相关阅读:
    从淘宝数据结构来看电子商务中商品属性设计
    YY淘宝商品数据库设计
    ElasticSearch-聚合bucket学习
    ElasticSearch-聚合bucket
    Elasticsearch(9) --- 聚合查询(Bucket聚合)
    Elasticsearch-多字段搜索(Multifield Search)和提高精确度
    五、设备管理与文件系统
    六、YUM仓库
    四、查找命令
    二、用户权限
  • 原文地址:https://www.cnblogs.com/zhanghaiyang/p/7213335.html
Copyright © 2011-2022 走看看