这个问题困扰了我半天的时间,下面我就把心路历程和代码粘上来,跟大家一起分享
关键的有两步:
1. assembly.xml配置文件和pom文件里的插件配置
首先pom文件里一定要先加上这个
maven-assembly-plugin插件配置,另外注意:看自己的项目目录,是否可以通过 src/main/assembly/assembly.xml找到assembly.xml文件。还有这里尽量不要用<pluginManagement>,否则无法打包成功,我也不知为何。
<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptor>src/main/assembly/assembly.xml</descriptor> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
2.第二步就是assembly.xml文件了
<?xml version="1.0" encoding="UTF-8"?> <assembly> <id>bin</id> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <dependencySets> <dependencySet> <useProjectArtifact>true</useProjectArtifact> <outputDirectory>lib</outputDirectory> </dependencySet> </dependencySets> <fileSets> <!--打包后的conf配置文件应包含项目的哪些配置文件,这里有一个springboot的yml文件和dubbo配置文件 directory标签里的是项目里的文件,outputDirectory标签里的是打包后文件的包目录--> <fileSet> <filtered>true</filtered> <directory>src/main/resources</directory> <outputDirectory>conf</outputDirectory> <includes> <include>application.yml</include> <include>dubbo-provider.xml</include> </includes> <fileMode>0644</fileMode> </fileSet> <!--打包后,将META-INF直接放在conf包下面--> <fileSet> <directory>src/main/resources/META-INF</directory> <outputDirectory>conf/META-INF</outputDirectory> <includes> <include>*</include> </includes> <fileMode>0644</fileMode> </fileSet> <!--将项目里scripts包里的shell运行脚本文件,打包后放在bin目录下--> <fileSet> <directory>src/main/scripts</directory> <outputDirectory>bin</outputDirectory> <includes> <include>run.sh</include> <include>start.sh</include> <include>stop.sh</include> </includes> <fileMode>0755</fileMode> <lineEnding>unix</lineEnding> </fileSet> </fileSets> </assembly>
以上是我的总结,我把我理解的都注释了,希望对新手有所帮助!如有疑问,可留言。