分模块设计即将一个项目分成几个模块开发
优点:方便项目的维护、管理和拓展,模块间相互调用,资源共享更方便
以前面的javaWeb项目为例,进行拆分
1.将原项目中的工具类拆分为一个独立的模块,在模块中创建相同的包存放工具类
在新模块的pom文件中引入所需依赖(jwt,阿里云oss,web起步依赖)
2.将项目中的实体类拆分为一个独立的模块,在模块中创建相同的包存放实体类
3.删除原项目中的jwt,阿里云oss依赖,引入工具类模块和实体类模块坐标
4.创建一个父工程,统一管理依赖,父工程的打包方式为pom文件方式,在原有的工程以及新建的模块中设置父工程坐标及相对路径,原项目的父工程坐标迁移到现父工程中,抽取子工程共有的依赖(lombok依赖)到父工程中去,子模块自动继承父工程的依赖,简化子模块依赖配置
5.在父工程中使用
6.将父工程设置为聚合工程,快速构建项目,使用
而后只需在聚合工程中构建项目即可实现多个模块的项目构建
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.7.5version>
<relativePath/>
parent>
<modules>
<module>../tlias-pojomodule>
<module>../tlias-utilsmodule>
<module>../tlias-web-managementmodule>
modules>
<groupId>com.sihfangroupId>
<artifactId>tlias-parentartifactId>
<version>1.0-SNAPSHOTversion>
<packaging>pompackaging>
<properties>
<maven.compiler.source>11maven.compiler.source>
<maven.compiler.target>11maven.compiler.target>
<lombok.version>1.18.24lombok.version>
<jjwt.version>0.9.1jjwt.version>
<aliyun.oss.version>3.15.1aliyun.oss.version>
<jaxb.version>2.3.1jaxb.version>
<activation.version>1.1.1activation.version>
<jaxb.runtime.version>2.3.3jaxb.runtime.version>
<fastJSON.version>1.2.76fastJSON.version>
<PageHelper.version>1.4.2PageHelper.version>
<mybatis.version>2.2.2mybatis.version>
properties>
<dependencies>
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
dependency>
dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jsonwebtokengroupId>
<artifactId>jjwtartifactId>
<version>0.9.1version>
dependency>
<dependency>
<groupId>com.aliyun.ossgroupId>
<artifactId>aliyun-sdk-ossartifactId>
<version>3.15.1version>
dependency>
<dependency>
<groupId>javax.xml.bindgroupId>
<artifactId>jaxb-apiartifactId>
<version>2.3.1version>
dependency>
<dependency>
<groupId>javax.activationgroupId>
<artifactId>activationartifactId>
<version>1.1.1version>
dependency>
<dependency>
<groupId>org.glassfish.jaxbgroupId>
<artifactId>jaxb-runtimeartifactId>
<version>2.3.3version>
dependency>
dependencies>
dependencyManagement>
<distributionManagement>
<repository>
<id>maven-releasesid>
<url>http://localhost:8081/repository/maven-releases/url>
repository>
<snapshotRepository>
<id>maven-snapshotsid>
<url>http://localhost:8081/repository/maven-snapshots/url>
snapshotRepository>
distributionManagement>
project>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<parent>
<artifactId>tlias-parentartifactId>
<groupId>com.shifangroupId>
<version>1.0-SNAPSHOTversion>
<relativePath>../tlias-parent/pom.xmlrelativePath>
parent>
<groupId>com.sihfangroupId>
<artifactId>tlias-pojoartifactId>
<version>1.0-SNAPSHOTversion>
<properties>
<maven.compiler.source>11maven.compiler.source>
<maven.compiler.target>11maven.compiler.target>
properties>
project>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<parent>
<artifactId>tlias-parentartifactId>
<groupId>com.shifangroupId>
<version>1.0-SNAPSHOTversion>
<relativePath>../tlias-parent/pom.xmlrelativePath>
parent>
<groupId>com.shifangroupId>
<artifactId>tlias-utilsartifactId>
<version>1.0-SNAPSHOTversion>
<properties>
<maven.compiler.source>11maven.compiler.source>
<maven.compiler.target>11maven.compiler.target>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>io.jsonwebtokengroupId>
<artifactId>jjwtartifactId>
dependency>
<dependency>
<groupId>com.aliyun.ossgroupId>
<artifactId>aliyun-sdk-ossartifactId>
dependency>
<dependency>
<groupId>javax.xml.bindgroupId>
<artifactId>jaxb-apiartifactId>
dependency>
<dependency>
<groupId>javax.activationgroupId>
<artifactId>activationartifactId>
dependency>
<dependency>
<groupId>org.glassfish.jaxbgroupId>
<artifactId>jaxb-runtimeartifactId>
dependency>
dependencies>
project>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<parent>
<artifactId>tlias-parentartifactId>
<groupId>com.shifangroupId>
<version>1.0-SNAPSHOTversion>
<relativePath>../tlias-parent/pom.xmlrelativePath>
parent>
<groupId>com.shifangroupId>
<artifactId>tlias-web-managementartifactId>
<version>0.0.1-SNAPSHOTversion>
<properties>
<java.version>11java.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>${mybatis.version}version>
dependency>
<dependency>
<groupId>com.mysqlgroupId>
<artifactId>mysql-connector-jartifactId>
<scope>runtimescope>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelper-spring-boot-starterartifactId>
<version>${PageHelper.version}version>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>fastjsonartifactId>
<version>${fastJSON.version}version>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-aopartifactId>
dependency>
<dependency>
<groupId>com.itheimagroupId>
<artifactId>tlias-pojoartifactId>
<version>1.0-SNAPSHOTversion>
dependency>
<dependency>
<groupId>com.itheimagroupId>
<artifactId>tlias-utilsartifactId>
<version>1.0-SNAPSHOTversion>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
架设在局域网内的仓库服务,用于解决团队内部的资源共享和资源同步问题
第一步配置:在maven的配置文件中配置访问私服的用户名、密码。
第二步配置:在maven的配置文件中配置连接私服的地址(url地址)。
第三步配置:在项目的pom.xml文件中配置上传资源的位置(url地址)。
配置好了上述三步之后,要上传资源到私服仓库,就执行执行maven生命周期:deploy。
私服仓库说明:
- RELEASE:存储自己开发的RELEASE发布版本的资源。
- SNAPSHOT:存储自己开发的SNAPSHOT发布版本的资源。
- Central:存储的是从中央仓库下载下来的依赖。
项目版本说明:
- RELEASE(发布版本):功能趋于稳定、当前更新停止,可以用于发行的版本,存储在私服中的RELEASE仓库中。
- SNAPSHOT(快照版本):功能不稳定、尚处于开发中的版本,即快照版本,存储在私服的SNAPSHOT仓库中。