Maven_使用maven创建多模块web项目 step by step

使用maven 创建多模块进销存项目结构
该文档结合一个现实的进销存(PSS )项目,对 maven 的如何创建管理项目结果进行了基本的描述。
阅读该文档需要有一定的项目模块管理的概念,以及基本的maven 知识,包括安装、配置等。
基本描述
该项目使用典型的三层架构,所以采用了pss-core 、 pss-model 、 pss-persist 、 pss-web 四个子项目。顾名思义, core 包含主要的程序代码, model 包含实体 POJO 类, persist 持久类( DAO ), web 包含一些 web 资源( js 、 jsp 、 vm... )。
除web 是打 war 包之外,其他的项目均是打 jar 包。
项目依赖关系图如下:
















1.  虚线表示模块依赖
2.  红色表示继承

实现步骤
创建项目目录
进入“工作空间”目录,创建名为PSS 的文件夹,切换至控制台,进入该文件夹。
配置模块
生成各个模块
该步骤会依次生成项目的各个模块,但是生成的模块并没有创建依赖,只是最简单的并且符合maven 要求的项目结构的模块,关于什么是 maven 的标准项目结构,可以参考 maven 官方文档,或者《 maven 权威指南》。
#app模块创建
mvn archetype:create -DgroupId=com.pubertersoft.pss.core -DartifactId=pss-core
#model模块创建
mvn archetype:create -DgroupId=com.pubertersoft.pss.model -DartifactId=pss-model
#persist模块创建
mvn archetype:create -DgroupId=com.pubertersoft.pss.persist -DartifactId=pss-persist
#web模块创建
mvn archetype:create -DgroupId=com.pubertersoft.pss.web -DartifactId=pss-web -DpackageName=com.pubertersoft.pss.web -DarchetypeArtifactId=maven-archetype-webapp
配置项目模块
在PSS 根目录下新建一个 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pubertersoft.pss</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<name>PSS Parent Project</name>
<version>1-SNAPSHOT</version>
<modules>
<module>pss-model</module>
<module>pss-core</module>
<module>pss-persist</module>
<module>pss-web</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

这里需要注意的是modules 节点,配置了上一步生成的四个模块。这样就组织起了其依赖关系。
生成好各个模块之后在pss 根目录下会生成四个目录,每个目录下都会有一个 pom.xml 的配置文件,将这些配置文件打开,删掉其中的 version 节点。添加 parent 节点,如下内容:
<parent>
<artifactId>parent</artifactId>
<groupId>com.pubertersoft.pss</groupId>
<version>1-SNAPSHOT</version>

</parent>

配置依赖
进入pss 根目录下的 pss-web 目录,在 pom.xml 文件中加入 dependencies 节点,加入如下内容:
<dependency>
<groupId>com.pubertersoft.pss.model</groupId>
<artifactId>pss-model</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.pubertersoft.pss.persist</groupId>
<artifactId>pss-persist</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.pubertersoft.pss.core</groupId>
<artifactId>pss-core</artifactId>
<version>${version}</version>
</dependency>


项目结构打包文件(pss.rar )。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值