maven 插件 assembly 打tar.gz包的详细过程
作者:摸鱼佬
这篇文章主要介绍了maven插件assembly打tar.gz包的详细过程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
maven 插件 assembly 打tar.gz包
GitHub: link. 欢迎star
注意:本篇博客风格(不多比比就是撸代码!!!)
一、项目目录
二、pom文件
1. profiles
<profiles> <profile> <id>dev</id> <properties> <profiles.active>dev</profiles.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <profiles.active>test</profiles.active> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>prod</id> <properties> <profiles.active>prod</profiles.active> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> </profiles>
2. plugins
<plugins> <plugin> <groupId>org.cyclonedx</groupId> <artifactId>cyclonedx-maven-plugin</artifactId> <version>2.5.3</version> </plugin> <!-- 配置assembly.xml文件路径 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.0</version> <configuration> <descriptors> <descriptor>src/assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layout>ZIP</layout> <includes> <!-- 项目启动jar包中排除依赖包 --> <include> <groupId>non-exists</groupId> <artifactId>non-exists</artifactId> </include> </includes> </configuration> </plugin> <!-- 自定义maven jar打包内容 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.1.0</version> <configuration> <archive> <manifest> <!-- 项目启动类 --> <mainClass>com.andon.springbootutil.SpringBootUtilApplication</mainClass> <classpathPrefix>../lib</classpathPrefix> <addClasspath>true</addClasspath> </manifest> </archive> </configuration> </plugin> <!-- 复制项目的依赖包到指定目录 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>target/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.1.0</version> </plugin> </plugins>
3. resource
<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>application.yml</include> <include>application-${profiles.active}.yml</include> <include>mapperxml/*.xml</include> <include>*.xml</include> <include>*.properties</include> <include>db/migration/*.sql</include> <include>banner.txt</include> </includes> </resource> </resources> <finalName>springboot-util</finalName>
三、assembly.xml
<?xml version="1.0" encoding="UTF-8" ?> <assembly> <id>release</id> <!-- 打包类型 --> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <fileSets> <!-- 输出bin目录所有文件到根目录 --> <fileSet> <directory>${basedir}/src/bin</directory> <outputDirectory>${file.separator}</outputDirectory> <fileMode>0755</fileMode> <includes> <include>**.sh</include> <include>**.bat</include> </includes> </fileSet> <!-- 输出配置文件到config目录 --> <fileSet> <directory>${basedir}/target/classes</directory> <outputDirectory>config</outputDirectory> <fileMode>0644</fileMode> <includes> <include>application.yml</include> <include>application-${profiles.active}.yml</include> <include>mapperxml/*.xml</include> <include>db/migration/*.sql</include> <include>*.xml</include> <include>*.properties</include> <include>banner.txt</include> </includes> </fileSet> <!-- 第三方依赖打包到lib目录 --> <fileSet> <directory>${basedir}/target/lib</directory> <outputDirectory>lib</outputDirectory> <fileMode>0755</fileMode> </fileSet> <!-- 将项目启动jar打包到boot目录 --> <fileSet> <directory>${basedir}/target</directory> <outputDirectory>boot</outputDirectory> <fileMode>0755</fileMode> <includes> <include>${project.build.finalName}.jar</include> </includes> </fileSet> <!-- 打包根目录下的文件 --> <fileSet> <directory>${basedir}</directory> <includes> <include>**.md</include> <include>**.conf</include> <include>**.zip</include> <include>**.zip</include> </includes> </fileSet> <fileSet> <directory>${basedir}/nginxconfig</directory> <outputDirectory>nginxconfig</outputDirectory> <includes> <include>*</include> </includes> </fileSet> <fileSet> <directory>${basedir}/nginx</directory> <outputDirectory>nginx</outputDirectory> <includes> <include>*</include> </includes> </fileSet> <fileSet> <directory>${basedir}/nginx/ssl</directory> <outputDirectory>nginx${file.separator}ssl</outputDirectory> <includes> <include>*</include> </includes> </fileSet> </fileSets> </assembly>
四、application.yml
server: port: 8866 servlet: context-path: /springboot-util forward-headers-strategy: native spring: profiles: active: @profiles.active@
五、启动脚本
1. start.sh
#!/bin/sh source /etc/profile APPLICATION="springboot-util" APPLICATION_JAR="${APPLICATION}.jar" JAVA_OPT="-server -XX:NewRatio=2 -XX:SurvivorRatio=8 -Xms8g -Xmx16g" JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow" JVM_REMOTE_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7766" nohup java ${JAVA_OPT} ${JVM_REMOTE_OPTS} -jar ./boot/${APPLICATION_JAR} > nohup.out 2>&1 &
2. stop.sh
#!/bin/sh APPLICATION="springboot-util" APPLICATION_JAR="${APPLICATION}.jar" PID=$(ps -ef | grep "${APPLICATION_JAR}" | grep -v grep | awk '{print $2}') kill -9 ${PID}
六、执行 mvn 打包命令
mvn clean package -DskipTests=true -P dev
七、tar.gz 包上传服务器并解压
八、执行 start.sh 启动脚本
九、访问 swagger
GitHub: link. 欢迎star
到此这篇关于maven 插件 assembly 打tar.gz包的文章就介绍到这了,更多相关maven assembly 打tar.gz包内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!