博客
关于我
Maven父子工程搭建详解
阅读量:385 次
发布时间:2019-03-05

本文共 6299 字,大约阅读时间需要 20 分钟。

Maven项目划分与依赖管理实例

项目结构与依赖管理

在实际项目中,尤其是大型项目,采用Maven进行模块化管理是非常常见的做法。通过合理划分模块,不仅可以提高代码的可维护性,还能更好地管理依赖关系。在本文中,我们将详细介绍如何构建一个包含多个模块的Maven项目,并配置模块之间的依赖关系。

父模块:aggregator

项目介绍

aggregator 项目作为父模块,主要负责聚合其他子模块,并提供公共的父模块功能。它本身并不含有实际的代码或资源文件,主要通过 pom.xml 文件进行配置。

pom.xml 配置

4.0.0
cn.jess.platform
aggregator
0.0.1-SNAPSHOT
pom
aggregator
../open-platform-common
../open-platform-web
../open-bug-m
nexus-snapshots
nexus distribution snapshot repository
http://127.0.0.1:8081/nexus/content/repositories/snapshots/
org.apache.maven.plugins
maven-resources-plugin
2.6
UTF-8
org.apache.maven.plugins
maven-compiler-plugin
2.5.1
UTF-8
1.6
1.6
com.sun
tools
1.6.0
system
${env.JAVA_HOME}/lib/tools.jar

子模块:open-platform-common

项目介绍

open-platform-common 项目是项目中使用到的公共Java类库。它作为一个JAR包进行打包,通常会被部署到Web应用的lib目录中。

pom.xml 配置

4.0.0
open-platform-common
jar
UTF-8
myRepository
local private nexus
http://127.0.0.1:8081/nexus/content/groups/public/
true
true
myPluginRepository
local private nexus
http://127.0.0.1:8081/nexus/content/groups/public/
true
false
cn.jess.platform
aggregator
0.0.1-SNAPSHOT
../aggregator

子模块:open-platform-web

项目介绍

open-platform-web 项目负责项目中使用到的公共Web文件,主要包含CSS和JavaScript文件。它作为WAR包进行打包,通常会被部署到Web应用的根目录下。

pom.xml 配置

4.0.0
open-platform-web
war
UTF-8
myRepository
local private nexus
http://127.0.0.1:8081/nexus/content/groups/public/
true
true
myPluginRepository
local private nexus
http://127.0.0.1:8081/nexus/content/groups/public/
true
false
cn.jess.platform
aggregator
0.0.1-SNAPSHOT
../aggregator

子模块:open-bug-m

项目介绍

open-bug-m 是最终要发布的应用项目。它作为WAR包进行打包,并依赖于open-platform-commonopen-platform-web 两个子模块。以下是其 pom.xml 文件的配置:

pom.xml 配置

open-bug-m
war
open-bug
最终要发布的应用
UTF-8
cn.jess.platform
aggregator
0.0.1-SNAPSHOT
../aggregator
myRepository
local private nexus
http://127.0.0.1:8081/nexus/content/groups/public/
true
true
myPluginRepository
local private nexus
http://127.0.0.1:8081/nexus/content/groups/public/
true
false
cn.jess.platform
open-platform-common
0.0.1-SNAPSHOT
jar
cn.jess.platform
open-platform-web
0.0.1-SNAPSHOT
war
open-bug
org.apache.maven.plugins
maven-war-plugin
2.3
WEB-INF/web.xml
cn.jess.platform
open-platform-web
org.codehaus.cargo
cargo-maven2-plugin
1.2.3
tomcat7x
F:\apache-tomcat-7.0.42(x64)
existing
F:\apache-tomcat-7.0.42(x64)
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787

项目部署

完成以上配置后,可以通过以下步骤进行项目部署:

  • 创建一个新的Maven项目
  • 在项目中添加必要的子模块(如上述的 aggregatoropen-platform-commonopen-platform-webopen-bug-m
  • 在每个子模块中添加适当的依赖配置
  • 运行 mvn install 将项目打包并部署
  • 注意:在部署 open-platform-web 项目时,确保 WEB-INF 目录下包含 web.xml 文件,以避免在执行 mvn 时出现错误。

    通过以上步骤,可以成功构建一个包含多个模块的Maven项目,并配置模块之间的依赖关系,从而实现项目的模块化管理和部署。

    转载地址:http://apig.baihongyu.com/

    你可能感兴趣的文章
    Oracle:ORA-00911: 无效字符
    查看>>
    Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
    查看>>
    Tensorflow.python.framework.errors_impl.ResourceExhaustedError:无法分配内存[操作:AddV2]
    查看>>
    TCP基本入门-简单认识一下什么是TCP
    查看>>
    tableviewcell 中使用autolayout自适应高度
    查看>>
    Symbolic Aggregate approXimation(SAX,符号聚合近似)介绍-ChatGPT4o作答
    查看>>
    Orcale表被锁
    查看>>
    svn访问报错500
    查看>>
    sum(a.YYSR) over (partition by a.hy_dm) 不需要像group by那样需要分组函数。方便。
    查看>>
    ORCHARD 是什么?
    查看>>
    Struts2中使用Session的两种方法
    查看>>
    Stream API:filter、map和flatMap 的用法
    查看>>
    STM32工作笔记0032---编写跑马灯实验---寄存器版本
    查看>>
    Static--用法介绍
    查看>>
    ssm旅游信息管理系统的设计与实现bus56(程序+开题)
    查看>>
    order by rand()
    查看>>
    SSM(Spring+SpringMvc+Mybatis)整合开发笔记
    查看>>
    ViewHolder的改进写法
    查看>>
    Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
    查看>>
    org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement profile
    查看>>