mvn cli 搭建项目架构
创建如图所示目录结构
在system-parent创建如下目录
├─system-dao
├─system-domain
├─system-service
└─system-web
创建system-parent
mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-parent -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
com.hbb0b0
system-parent
pom
1.0-SNAPSHOT
system-parent
http://maven.apache.org
junit
junit
3.8.1
test
system-domain
system-dao
system-service
system-web
说明
- system-parent 只需要 pom文件
- 修改
jar 为pom - 其中
节点的内容是子项目创建后自己加上去的,不用手工加
创建子项目 system-domain
mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-domain -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
pom.xml
<?xml version="1.0"?>
4.0.0
com.hbb0b0
system-parent
1.0-SNAPSHOT
system-domain
system-domain
jar
http://maven.apache.org
junit
junit
3.8.1
test
说明
- 去掉子项目
,去掉之后表示子项目的version,groupid 继承自 system-parent pom - 添加
jar
创建子项目 system-do
mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-dao -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
pom.xml
<?xml version="1.0"?>
4.0.0
com.hbb0b0
system-parent
1.0-SNAPSHOT
system-dao
jar
system-dao
http://maven.apache.org
junit
junit
3.8.1
test
com.hbb0b0
system-domain
${project.version}
说明
- 去掉子项目
,去掉之后表示子项目的version,groupid 继承自 system-parent pom - 添加
jar - system-dao 依赖 system-domain ,所以dependency 添加 system-domain 依赖
创建子项目 system-service
mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-service -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
pom.xml
<?xml version="1.0"?>
4.0.0
com.hbb0b0
system-parent
1.0-SNAPSHOT
system-service
system-service
jar
http://maven.apache.org
junit
junit
3.8.1
test
com.hbb0b0
system-dao
${project.version}
说明
- 去掉子项目
,去掉之后表示子项目的version,groupid 继承自 system-parent pom - 添加
jar - service 直接依赖 system-dao ,system-dao依赖system-domain,dependency 添加直接依赖 system-dao ,不需要添加system-domain 的依赖
创建子项目 system-web
mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false -DarchetypeCatalog=local
pom.xml
<?xml version="1.0"?>
4.0.0
com.hbb0b0
system-parent
1.0-SNAPSHOT
system-web
war
system-web Maven Webapp
http://maven.apache.org
junit
junit
3.8.1
test
com.hbb0b0
system-service
${project.version}
system-web
org.mortbay.jetty
maven-jetty-plugin
说明
- 去掉子项目
,去掉之后表示子项目的version,groupid 继承自 system-parent pom - 添加
jar - 添加 system-service 依赖
- 添加 jetty 插件 ,这样做的目的,让web项目直接在命令行运行
--修改 jsp文件 添加项目目录结构
清理与编译
在 system-parent目录运行
mvn clean install
执行成功之后 可以看到以下输出
[INFO] system-parent ...................................... SUCCESS [ 0.562 s]
[INFO] system-domain ...................................... SUCCESS [ 3.638 s]
[INFO] system-dao ......................................... SUCCESS [ 0.956 s]
[INFO] system-service ..................................... SUCCESS [ 0.956 s]
[INFO] system-web Maven Webapp ............................ SUCCESS [ 0.795 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.078 s
[INFO] Finished at: 2018-04-23T22:42:37+08:00
[INFO] Final Memory: 20M/192M
[INFO] ------------------------------------------------------------------------
运行web 项目
mvn jetty:run
运行成功之后控制台会输出一下信息
[INFO] jetty-6.1.26
[INFO] No Transaction manager fo
[INFO] Started SelectChannelConn
[INFO] Started Jetty Server
maven web project
浏览器结果
http://localhost:8080/system-web/
---system-dao
---system-domain
---system-service
---system-web