Maven properties属性进阶--资源过滤
来源:互联网 发布:郑州淘宝美工培训机构 编辑:程序博客网 时间:2024/06/05 20:17
maven的properties filter功能可以帮你自动替换配置文件中以${}包裹的变量。为了方便构建不同的环境,我们通常将不同的配置以properties形式配置在pom 中。默认情况下,Maven属性只有在POM中才会被解析。
资源过滤就是指让Maven属性在资源文件(src/main/resources、src/test/resources)中也能被解析。
在POM中添加下面的配置便可以开启资源过滤
<build> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <testResources> <testResource> <directory>${project.basedir}/src/test/resources</directory> <filtering>true</filtering> </testResource> </testResources> </build>
同时,通过不同的打包命令,也能实现在开发环境和发布环境中不同配置的设置
<properties> <!-- 开发阶段配置文件位置, 发布时打包加参数:-P product --> <scheduler.jdbc.config.path>classpath:config/jdbc.properties</scheduler.jdbc.config.path> <sys.jdbc.config.path>classpath:config/jdbc.properties</sys.jdbc.config.path> <system.config.path>classpath:config/system.properties</system.config.path></properties>
在profiles节点配置生产配置
<profiles> <!-- 发布时打包命令 clean package -P build tomcat7:run-war-only --> <profile> <id>product</id> <properties> <scheduler.jdbc.config.path>file:/home/config/base/jdbc-scheduler.properties</scheduler.jdbc.config.path> <sys.jdbc.config.path>file:/home/config/base/jdbc-sys.properties</sys.jdbc.config.path> <system.config.path>file:/home/config/base/system.properties</system.config.path> </properties> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <id>build</id> <build> <finalName>${project.name}</finalName> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build> </profile></profiles>
通过不同的打包命令,可打包成不同的配置:
mvn clean package -P product
mvn clean package -P build
配置好之后,在maven项目中都可以使用${sys.jdbc.config.path..等变量,支持过滤的xml和properties文件:
<bean class="org.xx.xx.PropertiesUtil"> <property name="locations"> <list> <value>${sys.jdbc.config.path}</value> <value>${system.config.path}</value> </list> </property></bean>
Maven除了可以对主资源目录、测试资源目录过滤外,还能对Web项目的资源目录(如css、js目录)进行过滤。这时需要对maven-war-plugin插件进行配置
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <webResources> <resource> <filtering>true</filtering> <directory>src/main/webapp</directory> <includes> <include>**/*.css</include> <include>**/*.js</include> </includes> </resource> </webResources> </configuration> </plugin>
阅读全文
0 0
- Maven properties属性进阶--资源过滤
- Maven资源过滤
- Maven 资源过滤
- maven的资源过滤
- Maven中properties属性
- maven:资源过滤的介绍
- maven 插件和资源过滤
- maven:资源过滤的介绍
- maven内置属性(${} properties)
- Maven内置了三大特性:属性、Profile和资源过滤来支持构建的灵活性。
- Maven内置了三大特性:属性、Profile和资源过滤来支持构建的灵活性。
- Maven内置了三大特性:属性、Profile和资源过滤来支持构建的灵活性。
- 依赖属性(Dependency Properties)进阶(一)
- 依赖属性(Dependency Properties)进阶(二)
- maven资源文件.properties的引用
- maven自定义属性给properties文件赋值
- Maven 实战 09 属性 资源
- Maven学习笔记(三)-maven移植和属性过滤
- 基于RNN的文本分类模型(Tensorflow)
- codeforces701A
- 编程能力七段论
- Nginx优化配置优化
- Spring Cloud学习--服务网关(Zuul 过滤器)
- Maven properties属性进阶--资源过滤
- 优傲机器人(Universal Robot)使用笔记
- IO其他流--处理流保留数据+基本数据类型
- AI_Scene classification 数据制作成TFrecord 格式
- python中的引用,深拷贝与浅拷贝
- 使用 Azure CLI 在 Azure China Cloud 云平台上手动部署一套 Cloud Foundry
- jQuery-ajax之load()方法
- Lock锁机制和synchronize分别实现生产者消费者例程
- spring+springMVC中使用@Transcational方式管理事务的配置方法