maven 之web项目的profile

有时候maven管理war项目,需要根据不同的环境,使用不同的配置文件。

pom.xml文件如下
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.chinaso</groupId>
<artifactId>test</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<url>http://maven.apache.org</url>
<properties>
<!--
不加下面这一行会报错
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
增加之后
Using 'UTF-8' encoding to copy filtered resources.
-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>

<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.7</version>
</dependency>
</dependencies>
<build>
<finalName>test</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<webResources>
<resource>
<!-- 元配置文件的目录,相对于pom.xml文件的路径 -->
<directory>${app_config_path}</directory>
<!-- 是否过滤文件,也就是是否启动auto-config的功能 -->
<filtering>false</filtering>
<!-- 目标路径 -->
<targetPath>WEB-INF/conf</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<properties>
<app_config_path>src/main/conf/dev</app_config_path>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<app_config_path>src/main/conf/test</app_config_path>
</properties>
</profile>
<profile>
<id>online</id>
<properties>
<app_config_path>src/main/conf/online</app_config_path>
</properties>
</profile>
</profiles>
</project>


打包命令
mvn clean package -Dmaven.test.skip=true -Pdev

输出日志
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ test ---
[INFO] Packaging webapp
[INFO] Assembling webapp [test] in [E:\x\test\target\y]
[INFO] Processing war project
[INFO] Copying webapp webResources [E:\E:\x\test\target\ysrc/main/conf/dev] to [E:\x\test\target\y]
[INFO] Copying webapp resources [E:\x\test\target\y\src\main\webapp]
[INFO] Webapp assembled in [4776 msecs]
[INFO] Building war: E:\x\test\target\vertical-search.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')


参考文章
http://lishuaibt.iteye.com/blog/614783
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫头哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值