maven 构建多模块项目

一、构建 maven 主工程

1、使用 idea 新建 Project,选择 maven,选择 quickstart 类型。 

 

点击 Next,填写 GroupId、ArtifactId。

GroupID是项目组织唯一的标识符,实际对应JAVA的包的结构,是main目录里java的目录结构。

ArtifactID就是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称。

 

 

点击 Next,选择 maven 相关版本,配置文件位置等。

 


 

点击 Next,选择项目存储目录,点击 Finish。

 


 

修改主工程 pom.xml 文件,把 packing 方式从 jar 改成 pom,如下图:

 

 

二、创建 maven module

建立 b2b2cweb、common、goods、goodsweb、customermgr 模块,其中 common、goods 是 quickstart 模块,b2b2cweb、goodsweb、customermgr 是 webapp 模块。

1、创建 b2b2cweb webapp 子模块

 

 填写模块名称,点击 next



 选择 org apache maven archetypes maven archetype webapp ,点击 next



 修改 package,点击 finish。

2、创建 common quickstart 子模块,选择 org apache maven archetypes maven archetype quickstart ,其他步骤与创建 b2b2cweb 相似。

3、创建 customermgr webapp 子模块,选择 org apache maven archetypes maven archetype webapp,其他步骤与创建 b2b2cweb 相似。

4、创建 goods quickstart 子模块,选择 org apache maven archetypes maven archetype quickstart ,其他步骤与创建 b2b2cweb 相似。

5、创建 goodsweb webapp 子模块,选择 org apache maven archetypes maven archetype webapp ,其他步骤与创建 b2b2cweb 相似。

三、配置模块间依赖关系

1、customermgr 模块 pom.xml 依赖关系



 2、 goods 模块 pom.xml  依赖关系

 

 3、goodsweb 模块 pom.xml 依赖关系



 

 4、b2b2cweb 模块 pom.xml 依赖关系



 

 5、在 b2b2cweb 模块中配置动态打包。



 

6、运行 Maven install,出现如下结果



 

四、使用 jetty 对工程进行测试

猜你喜欢

转载自512105256.iteye.com/blog/2283003