1.前言
2.项目pom配置
build><plugins><plugin><groupId>org.apache.maven.pluginsgroupId><artifactId>maven-jar-pluginartifactId><configuration><excludes><exclude>static/**exclude><exclude>*.propertiesexclude><exclude>*.xmlexclude><exclude>*.jsonexclude><exclude>*.yamlexclude><exclude>*.ymlexclude><exclude>*.pngexclude><exclude>*.txtexclude>excludes><archive><addMavenDescriptor>falseaddMavenDescriptor><manifest><addClasspath>trueaddClasspath><classpathPrefix>lib/classpathPrefix><useUniqueVersions>falseuseUniqueVersions><mainClass>com.dyyy.wechat.integration.web.WechatIntegrationWebApplicationmainClass>manifest><manifestEntries><Class-Path>./resources/Class-Path>manifestEntries>archive><outputDirectory>${project.build.directory}outputDirectory>configuration>plugin><plugin><groupId>org.apache.maven.pluginsgroupId><artifactId>maven-dependency-pluginartifactId><executions><execution><id>copy-dependenciesid><phase>packagephase><goals><goal>copy-dependenciesgoal>goals><configuration><outputDirectory>${project.build.directory}/lib/outputDirectory>configuration>execution>executions>plugin><plugin><artifactId>maven-resources-pluginartifactId><executions><execution><id>copy-resourcesid><phase>packagephase><goals><goal>copy-resourcesgoal>goals><configuration><resources><resource><directory>src/main/resourcesdirectory>resource>resources><outputDirectory>${project.build.directory}/resourcesoutputDirectory>configuration>execution>executions>plugin><plugin><groupId>org.springframework.bootgroupId><artifactId>spring-boot-maven-pluginartifactId><configuration><mainClass>xxx.xxx.Starter(项目的主类的全路径名--包名.类名)mainClass><classifier>execclassifier><includeSystemScope>trueincludeSystemScope><includes><include><groupId>nullgroupId><artifactId>nullartifactId>include>includes><layout>ZIPlayout><addResources>trueaddResources><outputDirectory>${project.build.directory}outputDirectory><skip>trueskip>configuration><executions><execution><goals><goal>repackagegoal>goals>execution>executions>plugin><plugin><groupId>org.apache.maven.pluginsgroupId><artifactId>maven-deploy-pluginartifactId><version>2.8.2version><configuration><skip>trueskip>configuration>plugin>plugins>build>
3.打包

4.发布

将该项目在nacos中的配置文件拷贝一份放入JAR路径中的application,yml中

将打包路径下的lib、resources和jar包拷贝到发布路径下:打出的jar只有37kb

在本机的JAR路径下运行项目:
java -Dfile.encoding=utf-8 -jar xxxxxx-SNAPSHOT.jar --spring.profiles.active=uat
5.遇到的问题及解决办法
5.1pom配置和启动参数指定有误导致如下:

解决:

这个地方配置为true就会报这个错,启动不用指定:-Djava.ext.dirs -Dloader.path -Dloader.path等配置参数,使用4中的运行命令直接回车即可。
5.2启动找不到主类
参看:https://blog.csdn.net/wm5920/article/details/85063894
pom配置如下:

5.3引入项目中的第三方jar打包

6.总结优化建议
上面拷贝发布的环节可以借助编写dockerfile构建项目镜像,然后使用jenkins编写构建流水线脚本构建项目,在借助私有hub仓库,每次构建的镜像都会推送到Hub私服上,然后使用K8S来管理容器,在有兴趣的话可以使用一款K8S的管理工具或平台,就不用每次去服务的黑窗口下使用K8S的命令来jenkins构建好的待发布项目了,到此是不是我们会有一个清晰连贯的思路和突发奇想的灵感了。
7.参考
https://blog.csdn.net/wm5920/article/details/85063894
https://blog.csdn.net/Feihongxiansen/article/details/103703055
https://blog.csdn.net/xishining/article/details/107421609
https://mp.weixin.qq.com/s/eqUPKIlM7SjJUGnVUjUmhw
https://blog.csdn.net/believe__sss/article/details/79517962
https://www.cnblogs.com/byron0918/p/4825343.html
https://blog.csdn.net/Keith_Walker/article/details/103527554
https://www.jianshu.com/p/5f10555636b6
https://blog.51cto.com/u_15175540/2787415?ivk_sa=1024320u