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 &
命令如上,具体可参考我上传的文件

原文地址:https://www.cnblogs.com/qdwyg2013/p/10305783.html

时间: 2024-07-30 11:06:53

spring-boot分环境打包为tar包的相关文章

spring-boot分环境打包为war包

1.启动类修改 @EnableSwagger2 @SpringBootApplication public class CustWebAcApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(CustWebAcApplication.class, args); } @Override protected SpringAppl

Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip

spring-boot-assembly 在spring boot项目中使用maven profiles和maven assembly插件根据不同环境打包成tar.gz或者zip 将spring boot项目中的配置文件提取到外部config目录中 将spring boot项目中的启动jar包移动到boot目录中 将spring boot项目中的第三方依赖jar包移动到外部lib目录中 bin目录中是启动,停止,重启服务命令 打包后的目录结构类似于tomcat/maven目录结构 GITHUB项

将 Spring boot 项目打成可执行Jar包,及相关注意事项(main-class、缺少 xsd、重复打包依赖)

最近在看 spring boot 的东西,觉得很方便,很好用.对于一个简单的REST服务,都不要自己部署Tomcat了,直接在 IDE 里 run 一个包含 main 函数的主类就可以了. 但是,转念一想,到了真正需要部署应用的时候,不可能通过 IDE 去部署啊.那有没有办法将 spring boot 的项目打包成一个可执行的 jar 包,然后通过 java -jar 命令去启动相应的服务呢? 很明显,是有的.下面,我把我自己的实践过程及遇到的问题,一 一说明一下. 首先,把项目的 POM 配置

Spring boot(4)-应用打包部署

摘自: http://blog.csdn.net/hguisu/article/details/51072683 1.Spring Boot内置web spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动.其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat).当然你也可以将项目打包成war包,放到独立的web容器中(Tomcat.weblogic等等),当然在此之前你要对程序入口做简单调整. 对server的几个常用的配

SpringBoot项目使用maven-assembly-plugin根据不同环境打包成tar.gz

spring-boot-assembly 在spring boot项目中使用maven profiles和maven assembly插件根据不同环境打包成tar.gz或者zip 将spring boot项目中的配置文件提取到外部config目录中 将spring boot项目中的启动jar包移动到boot目录中 将spring boot项目中的第三方依赖jar包移动到外部lib目录中 bin目录中是启动,停止,重启服务命令 打包后的目录结构类似于tomcat/maven目录结构 GITHUB项

spring boot 依赖环境和项目结构介绍

1.环境介绍 使用 Spring Boot 开发项目需要有两个基础环境和一个开发工具,这两个环境是指 Java 编译环境和构建工具环境,一个开发工具是指 IDE 开发工具. Spring Boot 2.0 要求 Java 8 作为最低版本,需要在本机安装 JDK 1.8 并进行环境变量配置,同时需要安装构建工具编译 Spring Boot 项目,最后准备个顺手的 IDE 开发工具即可. 1.1.构建工具 构建工具是一个把源代码生成可执行应用程序的自动化工具,Java 领域中主要有三大构建工具:A

前端自动分环境打包(vue和ant design)

现实中的问题:有时候版本上线的时候,打包时忘记切换环境,将测试包推上正式服务器,那你就会被批了. 期望:在写打包的命令行的时候就觉得自己在打包正式版本,避免推包时候的,不确信自己的包是否正确. 既然有了期望,那么就要开始百度如何去实现呢. 下面先开始介绍ant design的方法: ant design的打包工具是roadhog,那么从roadhog下手. 在roadhog文档中,发现define的配置可以传递给代码. 在ant design pro的issue中搜索中,发现环境变量的配置. 我

Vue项目分环境打包的实现步骤

转:https://blog.csdn.net/xinzi11243094/article/details/80521878 方法一:亲测真的有效 在项目开发中,我们的项目一般分为开发版.测试版.Pre版.Prod版.Vue-cli的默认环境一只有dev和prod两个,之前每次要发布测试版或Pre版都是修改了源码中API地址后打包,这样很麻烦.如果能根据不同环境打包就完美了.网上搜集了许多资料,现在可以分环境打包程序了,至于怎么打,接着住下看吧. 第1步:安装cross-env 在项目目录下运行

spring boot 开发环境搭建(Eclipse)

Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 spring boot 连接Mysql spring boot配置druid连接池连接mysql spring boot集成mybatis(1) spring boot集成mybatis(2) – 使用pagehelper实现分页 spring boot集成mybatis(3) – mybatis ge