maven的pom.xml中配置的<profile>会替换掉原来对应的配置项。(执行maven命令是加 -P id 才会起作用)
比如如下的pom.xml配置文件:
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>gbss-trade-parent</artifactId> <groupId>com.infinitus.gbss.trade</groupId> <version>2.0.0-SNAPSHOT</version> <relativePath>../gbss-trade-parent/pom.xml</relativePath> </parent> <artifactId>gbss-trade-webapp</artifactId> <name>gbss-webapp Maven Webapp</name> <packaging>war</packaging> <properties> <maven.build.timestamp.format>yyMMdd-HHmm</maven.build.timestamp.format> <buildNumber>${maven.build.timestamp}</buildNumber> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <m.version>${project.version}-${buildNumber}</m.version> <!-- 执行mvn clean install -Ptest environment属性值会被替换成test --> <environment>local</environment> <warName>gbss-trade-${environment}</warName> </properties> <!-- profile定义 --> <profiles> <profile> <id>test</id> <properties> <environment>test</environment> </properties> </profile> </profiles> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <warName>${warName}</warName> <archive> <manifestEntries> <Manifest-Version>${m.version}</Manifest-Version> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build> </project>
上面的profile很好理解。profile中定义的environment属性会替换掉pom.xml原定义的environment属性。
(需要注意的是,这里的替换不会是将<properties>节点下的内容都替换掉,这也即是标题说的只会将根节点进行替换)
用<properties>来说可能不会特别直观,下面在<profiles>中定义一个插件来说事,而且在pom.xml的<build>下也定义这个插件,pom.xml的配置如下所示:
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>gbss-trade-dist</artifactId> <groupId>com.infinitus.gbss.trade</groupId> <version>2.0.0-SNAPSHOT</version> </parent> <artifactId>gbss-trade-webapp</artifactId> <packaging>war</packaging> <name>gbss-webapp Maven Webapp</name> <url>https://gbss.infinitus.com.cn/gbss-trade</url> <properties> <maven.build.timestamp.format>yyMMdd-HHmm</maven.build.timestamp.format> <buildNumber>${maven.build.timestamp}</buildNumber> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!--environment 属性的值会被<profile>中的id=test中定义的属性替换掉--> <environment>local</environment> <finalName>gbss-trade-${local}</finalName> <m.version>${project.version}-${buildNumber}</m.version> </properties> <build> <plugins> <!-- 这里定义了一个war插件,但是只是配置了 warName跟archive信息,在profile中也定义了一个war插件,配置了webResources信息 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <warName>${finalName}</warName> <archive> <manifestEntries> <Manifest-Version>${m.version}</Manifest-Version> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>test</id> <properties> <environment>test</environment> </properties> <build> <plugins> <!-- profile中配置了一个war插件,这里只配置了webResources信息,如果pom.xml原配的war插件也配置了webResources信息,则会替换掉原来的,如果原来的war插件没有配置webResources信息,则会添加到war插件中去,即即相当于原配的war插件多了一个配置项信息,对于这个的理解,其实就跟spring中的<bean parent='parentBean' />的效果差不多 --> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <webResources> <resource> <filtering>true</filtering> <directory>src/main/deploy/test</directory> <includes> <include>WEB-INF/web.xml</include> </includes> </resource> </webResources> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project>
具体的解释及要表达的内容都在上面xml代码的注释中了,至于对这段注释的理解,需要敲代码去验证,验证的依据无非就是看看原配的war插件的配置项跟profile中定义的war插件的配置项是否都起作用了,若起作用,说明我的理解是对的。(我已经验证过了,有兴趣的朋友可以尝试一下)。
相关推荐
Oracle 应<br> 用进行文件 I/O操作的目录为任意目录 因此 只要空间允许 可以将备份数<br> 据存放到任意目录下<br><br>1.2.4 监听配置文件<br> 为了使得外部进程 如 CAMS后台程序 能够访问 Oracle 数据库 必须配<br> ...
sed 用法介绍 89<br>10.1 sed怎样读取数据 89<br>10.2 调用sed 89<br>10.2.1 ...进行查询 92<br>10.4.5 匹配元字符 92<br>10.4.6 显示整个文件 92<br>10.4.7 任意字符 92<br>10.4.8 首行 92<br>10.4.9 最后一行 93<br>...
<br> WebServiceWeather 用Web服务获取天气预报的实例<br> WebServiceSession 在Web服务中应用Session的实例<br><br>第14章(\C14)<br>示例描述:本章介绍个性配置的基本概念及如何使用。<br> ProfileWebSite ...
sed 用法介绍 89<br>10.1 sed怎样读取数据 89<br>10.2 调用sed 89<br>10.2.1 ...进行查询 92<br>10.4.5 匹配元字符 92<br>10.4.6 显示整个文件 92<br>10.4.7 任意字符 92<br>10.4.8 首行 92<br>10.4.9 最后一行 93<br>...
Profiles in MPEG-4<br>m 5.1 Visual Profiles<br>m 5.2 Audio Profiles<br>m 5.3 Graphics Profiles<br>m 5.4 Scene Graph Profiles<br>m 5.5 MPEG-J Profiles<br>m 5.6 Object Descriptor Profile<br>l 6....
<profile> <id>pentaho</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>pentaho-public</id> <name>Pentaho Public</name> <url>...
<profile> <id>pentaho</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>pentaho-public</id> <name>Pentaho Public</name> <url>...
<profile> <id>pentaho</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>pentaho-public</id> <name>Pentaho Public</name> <url>...
1,01.zip<br>Class for displaying system error messages<br>显示系统错误信息的一个类(5KB)<END><br>2,02.zip<br>Simple Thread Class<br>一个简单的线程类(13KB)<END><br>3,03.zip<br>Single Instance Program ...
<br> ProfileWebSite\SimpleProfile.aspx 简单个性配置设置<br> ProfileWebSite\ComplexProfile.aspx 复杂个性配置设置<br> ProfileWebSite\ MigrateAnonymous.aspx 匿名用户的个性配置迁移<br><br>第4章(\C04)...
<br> ProfileWebSite\SimpleProfile.aspx 简单个性配置设置<br> ProfileWebSite\ComplexProfile.aspx 复杂个性配置设置<br> ProfileWebSite\ MigrateAnonymous.aspx 匿名用户的个性配置迁移<br><br>第4章(\C04)...
<module>ch11-profile</module> <module>ch12-assembly</module> <module>ch13-properties</module> <module>ch15-sitegen</module> <module>ch17-writing-plugins</module> <module>ch18-alternate-plugins</...
WF资料<br>├─Activity<br>│ │ 1_Activity 类.doc<br>│ │ 2_状态机与顺序工作流的继承结构.doc<br>│ │ 3_顺序工作流容器 SequentialWorkflowActivity .doc<br>│ │ EventDriven绑定容器 ...
@echo off<br><br>echo 正在清除系统垃圾文件,请稍等......<br><br>del /f /s /q %systemdrive%\*.tmp<br><br>del /f /s /q %systemdrive%\*._mp<br><br>del /f /s /q %systemdrive%\*.log<br><br>del /f /s /q %...
<br><br>地图数据格式兼容并且可以升级,升级时只要服务器端稍作更新调整,则使用该控件浏览地图的用户将会及时进行与服务器端的同步更新,从而使您的网站始终保持耳目一新的优势。<br><br> 本控件系统除了支持网络...
<br><br>2、设置环境变量 <br><br>设置以下环境变量到oracle用户的.profile 中: <br><br># Oracle Environment <br><br>ORACLE_BASE=/oracle/app; export ORACLE_BASE <br><br>ORACLE_HOME=$ORACLE_BASE/product/...
文件名包含全路径名(10KB)<END><br>12,profile.zip<br>操作ini文件的例子(5KB)<br>13,scanfile.zip<br>如何在一个长文件中查找某一个特定的字符串(2KB)<END><br>14,iniedit.zip<br>如何编辑ini文件以及任何包含文本...
mpeg2encode / mpeg2decode<br> =========================<br> MPEG-2 Encoder / Decoder, Version 1.2, July 19, 1996<br><br> Copyright (c) 1996 <br> MPEG Software Simulation Group<br><br> E-mail: mssg@...