Springboot分布式手动打包部署—jar
1.项目结构
在这里
插入图片描述
2.关于common的打包
介绍:改模块抽取service所需要的公共资源,如token登录等等,不含有springboot的启动类
可能出现的错误:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.1.RELEASE:repackage (repackage) on project common_utils: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.2.1.RELEASE:repackage failed: Unable to find main class -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :common_utils
主要问题:repackage (repackage) on project common_utils: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.2.1.RELEASE:repackage failed: Unable to find main class -> [Help 1]
原因:common_utils的pom.xml包含了如下配置,去掉
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
3.关于service模块的打包
介绍:该模块为业务相关的模块,包含springboot的启动类
运行jar文件命令如下:java -jar xxx.jar
可能出现的问题,启动改模块的jar文件时报错如下:
C:\Users\32008\Desktop\competition - 副本\service\service-vod\target>java -jar service-vod-0.0.1-SNAPSHOT.jar
service-vod-0.0.1-SNAPSHOT.jar中没有主清单属性
原因:该模块的pom.xml没有包含如下配置,加上下面配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
4.打包命令:mvn clean package
打包成功的结果如下:
[INFO] Reactor Summary for guli_parent 0.0.1-SNAPSHOT:
[INFO]
[INFO] guli_parent ........................................ SUCCESS [ 0.231 s]
[INFO] common ............................................. SUCCESS [ 0.019 s]
[INFO] common_utils ....................................... SUCCESS [ 4.433 s]
[INFO] service_base ....................................... SUCCESS [ 3.240 s]
[INFO] service ............................................ SUCCESS [ 0.016 s]
[INFO] service-oss ........................................ SUCCESS [ 6.769 s]
[INFO] service-vod ........................................ SUCCESS [ 4.144 s]
[INFO] service-ucenter .................................... SUCCESS [ 6.379 s]
[INFO] service-front ...................................... SUCCESS [ 6.935 s]
[INFO] service-reception .................................. SUCCESS [ 7.643 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 40.307 s
[INFO] Finished at: 2021-04-18T23:47:50+08:00
[INFO] ------------------------------------------------------------------------
可能出现问题:如application.properties(springboot的配置文件)配置文件没有在jar中生效
解决方案:把application.properties拷贝到与打包出来的jar文件在同一级目录下,如:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Y7GD8P3i-1619188650814)(C:\Users\32008\AppData\Roaming\Typora\typora-user-images\1618761428364.png)]
5.打包的最终成果
…
…
6.源码地址
https://gitee.com/mhz-zzj/competition.git