maven打包插件
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><version>3.2.0</version><configuration><appendAssemblyId>false</appendAssemblyId><skipAssembly>false</skipAssembly><!--把最终的target包打在顶级目录--><outputDirectory>../target</outputDirectory><descriptors><!--指明描述符文件--><descriptor>src/main/assembly/assembly.xml</descriptor></descriptors></configuration><executions><execution><id>assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin>
assembly.xml内容:
<assembly><!--这里的id很重要,一定要与maven-assembly-plugin.executions.execution.id保持一致,否则不生效--><id>assembly</id><!--打包格式,支持dir:文件夹,zip:压缩包,tar.gz:压缩包--><formats><format>dir</format><format>zip</format></formats><!--是否包含根目录--><includeBaseDirectory>false</includeBaseDirectory><!--这里打包某些外部依赖的jar包--><fileSets><fileSet><directory>../dependcy</directory><outputDirectory>./</outputDirectory><includes><include>*.*</include></includes><fileMode>0644</fileMode></fileSet><!--这里将target输出到根目录--><fileSet><directory>target</directory><outputDirectory>./</outputDirectory><includes><include>*.jar</include></includes><fileMode>0755</fileMode></fileSet><!--这里打包一些启动、关闭的shell脚本--><fileSet><directory>src/main/bin</directory><outputDirectory>./</outputDirectory><includes><include>*.*</include></includes><fileMode>0755</fileMode></fileSet><!--这里打包特定目录下的文件,比如多环境支持的目录通过profile来实现不同环境下打包不同配置文件--><fileSet><directory>src/main/resources/${package.environment}/</directory><outputDirectory>./</outputDirectory><includes><include>application.properties</include></includes><fileMode>0644</fileMode></fileSet></fileSets><!--这里将项目依赖包全部输出到lib文件夹中--><dependencySets><dependencySet><outputDirectory>lib</outputDirectory></dependencySet></dependencySets></assembly>
打包完成后的目录如下
package--
--bin
--conf
--lib
程序启动路径
cd package
nohup java $JAVA_OPS -Dfile.encoding=UTF-8 -DappName=xxxName -cp ../conf/:../lib/* com.xxx.MyApplication >/dev/null 2>&1 &
在编译调试程序的时候我们采用POM中
<build><finalName>${app.name}</finalName><resources><resource><directory>src/main/resources</directory><filtering>true</filtering><includes><include>*.yml</include><include>*.xml</include><include>*.properties</include><include>mapping/*.*</include></includes></resource><resource><directory>src/main/resources/${package.environment}</directory><filtering>true</filtering><includes><include>*.*</include></includes></resource></resources></build>
在部署的时候采用以下POM配置
pom.xml 配置
<profiles><profile><id>dev</id><activation><activeByDefault>true</activeByDefault></activation><properties><package.environment>dev</package.environment></properties></profile><profile><id>test</id><properties><package.environment>test</package.environment></properties></profile><profile><id>prd</id><properties><package.environment>prd</package.environment></properties></profile><profile><id>pre</id><properties><package.environment>pre</package.environment></properties></profile></profiles>
如果觉得《Java服务-常用技术-maven-assembly-plugin打包springboot 打包目录结构及启动命令》对你有帮助,请点赞、收藏,并留下你的观点哦!