两种方式:
第一种方式:
父模块pom 不配置任何打包命令;
子模块(资源pom) 指定这个pom是资源类型;
子模块(服务pom) 指定这个pom是java服务类型;
1. 前提:
maven对应多个子项目, 每个子项目都是一个单独运行的jar包
2. 项目结构:
五个 jar包; 一个common资源包
3. 思路:
common 作为这五个jar的外部资源
五个jar单独导报
4: 配置
父级pom配置: 不可以加这个! 不可以加! 不可以加!
<build><plugins><plugin><!-- 父级pom 不要加这个 --><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
common-pom配置: 加资源配置
<build><plugins><!-- 资源文件拷贝插件 , 指定common 是资源, 不需要被打包, 谁(jar)用谁引用--><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><configuration><encoding>UTF-8</encoding></configuration></plugin></plugins></build>
子项目-pom配置: 指定打包和main入口
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><mainClass>com.a.b.Main(main方法启动类路径)</mainClass></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build>
5: 打包
在父-pom的路径下使用这个命令:
#在父级pom的路径下#打包 mvn clean package -Dmaven.test.skip=true
6: 去子项目的target目录下找对应的 *.jar包
第二种方式:
父级pom使用 'maven-compiler-plugin' 工具打包;
子模块(资源类型): 不需要配置pom文件, 但是要把子模块依赖到 父模块的pom中;
子模块(java类型): 需要配置pom文件: 'spring-boot-maven-plugin', 同时挂在父pom中;
1. 项目背景:
2. 介绍
上面的服务分两种:
common: 就是各种资源
modules: 就是各种jar包
3. 配置
父级(最大的那个pom)配置如下
<build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build>
同时把common下面的子包 和 modules下面的子包 都给 引入到父级pom(最大的那个pom)
如下:
4. 修改需要运行的jar类型子pom
<build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build>