spring-boot分环境打包为tar包
1.pom配置
<!-- 多环境打包 start --> <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> </profile> <!-- 正式环境 --> <profile> <id>online</id> <properties> <profiles.active>online</profiles.active> </properties> </profile> </profiles> <!-- 多环境打包 end --> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.class</include> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>*.xml</include> <include>*.properties</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources/conf/${profiles.active}</directory> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <configuration> <!-- 生成的tar.gz文件的名字,如果没有设置就默认用pom文件里的artifactId+version--> <finalName>${project.artifactId}</finalName> <!-- 属性控制是否在生成的打包文件的文件名中包含assembly id --> <appendAssemblyId>false</appendAssemblyId> <descriptors> <!--描述文件路径--> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <!-- 绑定到package生命周期阶段上 --> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
2.assembly.xml文件
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> <id>dist</id> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <fileSets> <fileSet> <directory>src/main/bin</directory> <outputDirectory>bin</outputDirectory> <directoryMode>0777</directoryMode> <includes> <include>**/*</include> </includes> <fileMode>0777</fileMode> <lineEnding>unix</lineEnding> </fileSet> <fileSet> <directory>target/classes</directory> <outputDirectory>conf</outputDirectory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <excludes> <exclude>**/*.class</exclude> </excludes> </fileSet> </fileSets> <dependencySets> <!-- copy all third party jars to lib folder. --> <dependencySet> <outputDirectory>lib</outputDirectory> <excludes> <exclude>com.dangdang:*</exclude> </excludes> </dependencySet> <!-- copy all dangdang jars to app folder. --> <dependencySet> <outputDirectory>app</outputDirectory> <includes> <include>com.dangdang:*</include> </includes> <fileMode>0644</fileMode> </dependencySet> </dependencySets> </assembly>
3.启动脚本
nohup java -classpath lib路径:conf路径:app路径:. 启动类 > /dev/null 2>&1 &
命令如上,具体可参考我上传的文件