使用Maven构建多模块项目.docx

上传人:b****3 文档编号:5346740 上传时间:2022-12-15 格式:DOCX 页数:14 大小:16.72KB
下载 相关 举报
使用Maven构建多模块项目.docx_第1页
第1页 / 共14页
使用Maven构建多模块项目.docx_第2页
第2页 / 共14页
使用Maven构建多模块项目.docx_第3页
第3页 / 共14页
使用Maven构建多模块项目.docx_第4页
第4页 / 共14页
使用Maven构建多模块项目.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

使用Maven构建多模块项目.docx

《使用Maven构建多模块项目.docx》由会员分享,可在线阅读,更多相关《使用Maven构建多模块项目.docx(14页珍藏版)》请在冰豆网上搜索。

使用Maven构建多模块项目.docx

使用Maven构建多模块项目

使用Maven构建多模块项目

  在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为domain(域模型层)、dao(数据库访问层)、service(业务逻辑层)、web(表现层),这样分层之后,各个层之间的职责会比较明确,后期维护起来也相对比较容易,今天我们就是使用Maven来构建以上的各个层。

  项目结构如下:

  system-parent

    |----pom.xml

    |----system-domain

        |----pom.xml

    |----system-dao

        |----pom.xml

    |----system-service

        |----pom.xml

    |----system-web

        |----pom.xml

一、创建system-parent项目

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

  进入命令行,输入以下命令:

mvnarchetype:

create-DgroupId=me.gacl-DartifactId=system-parent-DarchetypeArtifactId=maven-archetype-quickstart-DinteractiveMode=false

  

  命令执行完成之后可以看到在当前目录(C:

\DocumentsandSettings\Administrator)生成了system-parent目录,里面有一个src目录和一个pom.xml文件,

将src文件夹删除,然后修改pom.xml文件,将jar修改为pom,pom表示它是一个被继承的模块,

1

//maven.apache.org/POM/4.0.0"xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

2xsi:

schemaLocation="http:

//maven.apache.org/POM/4.0.0http:

//maven.apache.org/xsd/maven-4.0.0.xsd">

34.0.0

4

5me.gacl

6system-parent

71.0-SNAPSHOT

8pom

9

10system-parent

11http:

//maven.apache.org

12

13

14UTF-8

15

16

17

18

19junit

20junit

213.8.1

22test

23

24

25

复制代码

二、创建sytem-domain模块

  在命令行进入创建好的system-parent目录,然后执行下列命令:

mvnarchetype:

create-DgroupId=me.gacl-DartifactId=system-domain-DarchetypeArtifactId=maven-archetype-quickstart-DinteractiveMode=false

  

命令执行完成之后可以看到在system-parent目录中生成了system-domain,里面包含src目录和pom.xml文件。

  同时,在system-parent目录中的pom.xml文件自动添加

system-domain

  这时,system-parent的pom.xml文件如下:

复制代码

1

xmlversion="1.0"encoding="UTF-8"?

>

2

//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.0http:

//maven.apache.org/xsd/maven-4.0.0.xsd">

34.0.0

4

5me.gacl

6system-parent

71.0-SNAPSHOT

8pom

9

10system-parent

11http:

//maven.apache.org

12

13

14UTF-8

15

16

17

18

19junit

20junit

213.8.1

22test

23

24

25

26system-domain

27

28

复制代码

  修改system-domain目录中的pom.xml文件,把me.gacl1.0-SNAPSHOT去掉,加上jar,因为groupId和version会继承system-parent中的groupId和version,packaging设置打包方式为jar

1

xmlversion="1.0"?

>

2

schemaLocation="http:

//maven.apache.org/POM/4.0.0http:

//maven.apache.org/xsd/maven-4.0.0.xsd"xmlns="http:

//maven.apache.org/POM/4.0.0"

3xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance">

44.0.0

5

6me.gacl

7system-parent

81.0-SNAPSHOT

9

10

11system-domain

12jar

13

14system-domain

15http:

//maven.apache.org

16

复制代码

三、创建sytem-dao模块

  在命令行进入创建好的system-parent目录,然后执行下列命令:

mvnarchetype:

create-DgroupId=me.gacl-DartifactId=system-dao-DarchetypeArtifactId=maven-archetype-quickstart-DinteractiveMode=false

  

  命令执行完成之后可以看到在system-parent目录中生成了system-dao,里面包含src目录和pom.xml文件。

  同时,在system-parent目录中的pom.xml文件自动变成

复制代码

1

xmlversion="1.0"encoding="UTF-8"?

>

2

//maven.apache.org/POM/4.0.0"xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"xsi:

schemaLocation="http:

//maven.apache.org/xsd/maven-4.0.0.xsd">

34.0.0

4

5me.gacl

6system-parent

71.0-SNAPSHOT

8pom

9

10system-parent

11http:

//maven.apache.org

12

13

14UTF-8

15

16

17

18

19junit

20junit

213.8.1

22test

23

24

25

26system-domain

27system-dao

28

29

复制代码

  修改system-dao目录中的pom.xml文件,,把me.gacl1.0-SNAPSHOT去掉,加上jar,因为groupId和version会继承system-parent中的groupId和version,packaging设置打包方式为jar,同时添加对system-domain模块的依赖,修改后的内容如下:

复制代码

1

xmlversion="1.0"?

>

2

schemaLocation="http:

//maven.apache.org/POM/4.0.0http:

//maven.apache.org/xsd/maven-4.0.0.xsd"xmlns="http:

//maven.apache.org/POM/4.0.0"

3xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance">

44.0.0

5

6me.gacl

7system-parent

81.0-SNAPSHOT

9

10

11system-dao

12jar

13

14system-dao

15http:

//maven.apache.org

16

17UTF-8

18

19

20

--system-dao需要使用到system-domain中的类,所以需要添加对system-domain模块的依赖-->

21

22me.gacl

23system-domain

24${project.version}

25

26

27

复制代码

四、创建system-service模块

  在命令行进入创建好的system-parent目录,然后执行下列命令:

mvnarchetype:

create-DgroupId=me.gacl-DartifactId=system-service-DarchetypeArtifactId=maven-archetype-quickstart-DinteractiveMode=false

  如下图所示:

  

  命令执行完成之后可以看到在system-parent目录中生成了system-service,里面包含src目录和pom.xml文件。

  

  同时,在system-parent目录中的pom.xml文件自动变成

复制代码

1

xmlversion="1.0"encoding="UTF-8"?

>

2

//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.0http:

//maven.apache.org/xsd/maven-4.0.0.xsd">

34.0.0

4

5me.gacl

6system-parent

71.0-SNAPSHOT

8pom

9

10system-parent

11http:

//maven.apache.org

12

13

14UTF-8

15

16

17

18

19junit

20junit

213.8.1

22test

23

24

25

26system-domain

27system-dao

28system-service

29

30

复制代码

  修改system-service目录中的pom.xml文件,,把me.gacl1.0-SNAPSHOT去掉,加上jar,因为groupId和version会继承system-parent中的groupId和version,packaging设置打包方式为jar,同时添加对system-dao模块的依赖,system-service依赖system-dao和system-domain,但是我们只需添加system-dao的依赖即可,因为system-dao已经依赖了system-domain。

复制代码

1

xmlversion="1.0"?

>

2

schemaLocation="http:

//maven.apache.org/POM/4.0.0http:

//maven.apache.org/xsd/maven-4.0.0.xsd"xmlns="http:

//maven.apache.org/POM/4.0.0"

3xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance">

44.0.0

5

6me.gacl

7system-parent

81.0-SNAPSHOT

9

10

11system-service

12jar

13

14system-service

15http:

//maven.apache.org

16

17UTF-8

18

19

20

--

21system-service依赖system-dao和system-domain,

22但是我们只需添加system-dao的依赖即可,因为system-dao已经依赖了system-domain

23-->

24

25me.gacl

26system-dao

27${project.version}

28

29

30

复制代码

五、创建system-web模块

  在命令行进入创建好的system-parent目录,然后执行下列命令:

mvnarchetype:

create-DgroupId=me.gacl-DartifactId=system-web-DarchetypeArtifactId=maven-archetype-webapp-DinteractiveMode=false

  如下图所示:

  

  命令执行完成之后可以看到在system-parent目录中生成了system-web,里面包含src目录和pom.xml文件。

如下图所示:

  

  在\system-web\src\main\webapp目录中还生成了一个简单的index.jsp,如

HelloWorld!

  system-web\src\main\webapp\WEB-INF目录中生成了web.xml

  同时,在system-parent目录中的pom.xml文件自动变成

1

xmlversion="1.0"encoding="UTF-8"?

>

2

//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.0http:

//maven.apache.org/xsd/maven-4.0.0.xsd">

34.0.0

4

5me.gacl

6system-parent

71.0-SNAPSHOT

8pom

9

10system-parent

11http:

//maven.apache.org

12

13

14UTF-8

15

16

17

18

19junit

20junit

21

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1