SpringBoot Maven打包如何根据环境排除文件
更新时间:2024年12月09日 09:02:09 作者:保持充电
文章介绍了在SpringBoot项目中,根据不同的环境(开发、测试、生产)进行JSP文件打包处理的方法,通过配置`pom.xml`文件中的``标签,可以实现开发环境保留`index.jsp`文件,测试环境和生产环境排除该文件
需求背景
最近在项目上有个需求,要求把生产环境中的某些文件下掉,测试环境要保留,文件不能删,所以就在打包的时候做处理,项目中是jsp文件,废话不多说
项目结构
SpringBoot 2.6.1、JDK 1.8
dev
:开发环境lst
:测试环境procloud
:生产环境
项目pom.xml文件配置(maven)
<build> 标签
<profiles>标签(多环境需要)
profiles 下的子标签 profile,每个子标签对应一个环境
测试环境打包保留index.jsp
生产环境打包排除index.jsp
最终pom.xml文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>iss-manager</artifactId> <name>iss-manager</name> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <!-- jasper --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <!--<scope>provided</scope>--> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> </dependency> </dependencies> <build> <finalName>iss-manager</finalName> <resources> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.yaml</include> </includes> </resource> <resource> <directory>src/main/resources/</directory> <filtering>false</filtering> <includes> <include>static/</include> <include>templates/</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.4.2.RELEASE</version> <configuration> <executable>true</executable> </configuration> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>utf-8</encoding> <useDefaultDelimiters>true</useDefaultDelimiters> </configuration> </plugin> </plugins> </build> <profiles> <profile> <!-- 测试环境 --> <id>lst</id> <properties> <profileActive>lst</profileActive> </properties> <build> <!-- 资源文件管理--> <resources> <resource> <directory>src/main/webapp</directory> <includes> <include>**/*.*</include> </includes> <filtering>true</filtering> <targetPath>META-INF/resources</targetPath> <excludes> <exclude>**/*.woff</exclude> <exclude>**/*.woff2</exclude> <exclude>**/*.ttf</exclude> <exclude>**/*.eot</exclude> <exclude>**/*.svg</exclude> <exclude>**/*.docx</exclude> </excludes> </resource> <resource> <directory>src/main/webapp</directory> <includes> <include>**/*.*</include> <include>**/*.woff</include> <include>**/*.woff2</include> <include>**/*.ttf</include> <include>**/*.eot</include> <include>**/*.svg</include> </includes> <filtering>false</filtering> <targetPath>META-INF/resources</targetPath> </resource> </resources> </build> </profile> <profile> <!-- 生产环境--> <id>procloud</id> <properties> <profileActive>procloud</profileActive> </properties> <build> <!-- 资源文件管理--> <resources> <resource> <directory>src/main/webapp</directory> <includes> <include>**/*.*</include> </includes> <filtering>true</filtering> <targetPath>META-INF/resources</targetPath> <excludes> <exclude>**/*.woff</exclude> <exclude>**/*.woff2</exclude> <exclude>**/*.ttf</exclude> <exclude>**/*.eot</exclude> <exclude>**/*.svg</exclude> <exclude>**/*.docx</exclude> <!-- 生产环境打包排除index.jsp文件 --> <exclude>**/index.jsp</exclude> </excludes> </resource> <resource> <directory>src/main/webapp</directory> <includes> <include>**/*.*</include> <include>**/*.woff</include> <include>**/*.woff2</include> <include>**/*.ttf</include> <include>**/*.eot</include> <include>**/*.svg</include> </includes> <filtering>false</filtering> <targetPath>META-INF/resources</targetPath> <excludes> <!-- 生产环境打包排除index.jsp文件 --> <exclude>**/index.jsp</exclude> </excludes> </resource> </resources> </build> </profile> </profiles> </project>
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
SpringBoot集成yitter-idgenerator(雪花漂移)分布式Id自增的实现
本文主要介绍了SpringBoot集成yitter-idgenerator(雪花漂移)分布式Id自增的实现,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2022-01-01Springboot整合RabbitMq测试TTL的方法详解
这篇文章主要介绍了Springboot整合RabbitMq测试TTL的设置,设置TTL一般由两种设置方法,设置整个队列的过期时间另一种设置单个消息的过期时间,通过示例图文相结合给大家介绍的非常详细,需要的朋友可以参考下2022-03-03浅谈JDK8中的Duration Period和ChronoUnit
在JDK8中,引入了三个非常有用的时间相关的API:Duration,Period和ChronoUnit。他们都是用来对时间进行统计的,本文将会详细讲解一下这三个API的使用2021-06-06基于spring boot 1.5.4 集成 jpa+hibernate+jdbcTemplate(详解)
下面小编就为大家带来一篇基于spring boot 1.5.4 集成 jpa+hibernate+jdbcTemplate(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-06-06详解springboot中redis的使用和分布式session共享问题
这篇文章主要介绍了详解springboot中redis的使用和分布式session共享问题,详细的介绍了解决分布式系统的session如何共享问题,有兴趣的可以了解一下2017-11-11
最新评论