本文主要是介绍SpringBoot2.0.4 Maven 多模块 打包 解决elasticsearch子模块不能打包问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一个多模块项目 如下图所示:
其中:主项目 qqkj-parent
项目主入口:qqkj-web
pom文件中主要修改:
qqkj-parent ----pom文件:
注意:父项目的打包形式为 pom
build修改:
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>${java.version}</source><target>${java.version}</target></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.19.1</version><configuration><skipTests>true</skipTests> <!--默认关掉单元测试 --></configuration></plugin></plugins>
</build>
程序主入口修改:qqkj-web -- pom
只需要修改build 如下
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><!-- 指定该Main Class为全局的唯一入口 --><mainClass>com.czxy.QqkjWebApplication</mainClass><layout>ZIP</layout></configuration><executions><execution><goals><goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中--></goals></execution></executions></plugin></plugins>
</build>
注意如果你的项目中有整合Elasticsearch模块 的如果在Service模块下依赖Elasticsearch模块和 dao模块在
打包过程中会出错 具体原因不知
解决办法:在Service 模块下删除原先引入的elasticsearch 模块在引入elasticsearch 的启动器 把原先有关Elasticsearch模块的包和类导入Service下即可
程序主入口的 application.properties下加入elasticsearch配置
# ES
spring.data.elasticsearch.repositories.enabled = true
spring.data.elasticsearch.cluster-nodes = 127.0.0.1:9300
最后那里有引用原先Elasticsearch模块的稍微修改包路径即可
service 导入Elasticsearch模块的包和类
删除原先引入的elasticsearch 模块在引入elasticsearch 的启动器
打包:
成功:
这篇关于SpringBoot2.0.4 Maven 多模块 打包 解决elasticsearch子模块不能打包问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!