- 浏览: 211397 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
Wangwei86609:
非常好的规则引擎框架,支持决策树和多线程运行规则https:/ ...
规则引擎 -
hzxlb910:
真详细,收藏哈
maven setting.xml配置说明 -
东方胜:
[b][/b]
脚本语言 Tcl -
345161974:
hyw520110 写道345161974 写道这个Visua ...
Visual Tcl Binary 完整版(完美中文支持) -
hyw520110:
345161974 写道这个Visual Tcl Binary ...
Visual Tcl Binary 完整版(完美中文支持)
首先简单介绍下 Maven 的 profile 是什么。对于人来说,profile 是指人的肖像,轮廓,比如论坛里每个人注册了帐号后,可以设置自己的 profile,放上照片,介绍等等。对于 Maven 来说又是怎样呢?整个项目定义好了项目对象模型(POM),就像论坛为每个人提供了默认的行为功能,如果我想改变我机器上的 POM 呢?这时就可以使用 profile。下面举个例子:
- <profiles>
- <profile>
- <id>jdk16</id>
- <activation>
- <jdk>1.6</jdk>
- </activation>
- <modules>
- <module>simple-script</module>
- </modules>
- </profile>
- </profiles>
<profiles> <profile> <id>jdk16</id> <activation> <jdk>1.6</jdk> </activation> <modules> <module>simple-script</module> </modules> </profile> </profiles>
这个 profile 的意思是,当机器上的 JDK 为1.6的时候,构建 simple-script 这个子模块,如果是1.5或者1.4,那就不构建,这个 profile 是由环境自动激活的。
我们需要在合适的地方使用合适的 profile ,并且在合适的时候用合适的方式将其激活,你不能在构建服务器上激活非公共的 profile,你也不能要求开发人员写很复杂的命令来使用常规的 profile。因此这里介绍一下几种 profile 的激活方式。
1. 根据环境自动激活。
如前一个例子,当 JDK 为1.6的时候,Maven 就会自动构建 simple-script 模块。除了 JDK 之外,我们还可以根据操作系统参数和 Maven 属性等来自动激活 profile,如:
- <profile>
- <id>dev</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- <jdk>1.5</jdk>
- <os>
- <name>Windows XP</name>
- <family>Windows</family>
- <arch>x86</arch>
- <version>5.1.2600</version>
- </os>
- <property>
- <name>mavenVersion</name>
- <value>2.0.5</value>
- </property>
- <file>
- <exists>file2.properties</exists>
- <missing>file1.properties</missing>
- </file>
- </activation>
- ...
- </profile>
<profile> <id>dev</id> <activation> <activeByDefault>false</activeByDefault> <jdk>1.5</jdk> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> <property> <name>mavenVersion</name> <value>2.0.5</value> </property> <file> <exists>file2.properties</exists> <missing>file1.properties</missing> </file> </activation> ... </profile>
2. 通过命令行参数激活。
这是最直接和最简单的方式,比如你定义了一个名为 myProfile 的 profile,你只需要在命令行输入 mvn clean install -Pmyprofile 就能将其激活,这种方式的好处很明显,但是有一个很大的弊端,当 profile 比较多的时候,在命令行输入这写 -P 参数会让人觉得厌烦,所以,如果你一直用这种方式,觉得厌烦了,可以考虑使用其它自动激活的方式。
3. 配置默认自动激活。
方法很简单,在配置 profile 的时候加上一条属性就可以了,如:
- <profile>
- <id>dev</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- ...
- </profile>
<profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> ... </profile>
在一个特殊的环境下,配置默认自动激活的 profile 覆盖默认的 POM 配置,非常简单有效。
4. 配置 settings.xml 文件 profile 激活。
settings.xml 文件可以在 ~/.m2 目录下,为某个用户的自定义行为服务,也可以在 M2_HOME/conf 目录下,为整台机器的所有用户服务。而前者的配置会覆盖后者。同理,由 settings.xml 激活的 profile 意在为用户或者整个机器提供特定环境配置,比如,你可以在某台机器上配置一个指向本地数据库 URL 的 profile,然后使用该机器的 settings.xml 激活它。激活方式如下:
- <settings>
- ...
- <activeProfiles>
- <activeProfile>local_db</activeProfile>
- </activeProfiles>
- </settings>
<settings> ... <activeProfiles> <activeProfile>local_db</activeProfile> </activeProfiles> </settings>
Maven 提供的 profile 功能非常强大和灵活,用得好的话,可以有效的隔离很多特殊的配置,使得整个项目能在不同环境中顺利的构建。但是,强大和灵活带来得问题是相对难掌握,希望本文能对 Maven 使用者有帮助。
发表评论
-
Maven Artifacts如何部署到仓库
2012-03-28 11:50 936http://www.blogjava.net/lishunl ... -
maven常见问题问答
2011-11-16 13:24 718前言 Maven,发音是[`meivin],"专家 ... -
maven setting.xml配置说明
2011-11-16 12:43 1263setting.xml view plain ... -
Maven实战指南:“打包”的技巧
2011-10-11 10:13 2025http://tech.it168.com/a2011/062 ... -
M2工程 mvn deploy 401 403错误处理
2011-10-10 15:11 1064http://hi.baidu.com/g4_gc/blog ... -
maven部署web工程基础步骤
2011-10-10 12:43 19861.准备工作 下载maven(url:http://a ... -
eclipse maven wtp jar/lib deploy
2011-10-09 09:57 984eclipse工程(with maven & wtp) ... -
配置Maven web项目
2011-09-13 16:00 9091、创建Web应用 mvn archetype:genera ... -
maven报错:mvn deploy
2011-09-09 14:01 1615一.Error deploying artifact: ... -
maven配置篇之pom.xml
2011-09-08 15:24 756说完了settings.xml配置, ... -
简述maven中的profiles
2011-09-08 15:06 921Profiles是maven的一个很关键的术语:profile ... -
maven项目添加jar包.
2011-08-16 09:31 1114很多新手都不知道如何在maven项目里添加jar包. 以前我还 ... -
Hudson+Maven+SVN 快速搭建持续集成环境
2011-05-26 14:09 962原: http://www.blogjava.net ... -
基于maven和hudson打造持续集成环境
2011-05-26 12:58 1044对持续集成的需求 对持续集成的需求主要来自项目过程的痛,在 ... -
maven 配置篇 之 settings.xml
2011-05-24 20:36 832maven2 比起maven1 来说,需要配置的文件少多了,主 ... -
Maven生命周期详解
2011-05-24 17:47 651Maven强大的一个重要的 ... -
使用Profile和Resources Filter隔离测试环境
2011-05-24 17:42 782Maven能够帮我们很好的 ... -
使用maven-sql-plugin实现持续数据库集成(CDBI)
2011-05-24 17:41 911数据库持续集成(Continuous Database Int ... -
Maven最佳实践:版本管理
2011-05-24 16:32 762原文:http://juvenshun.iteye ... -
Maven仓库
2011-05-24 16:30 809什么是Maven仓库 在不用Maven的时候,比如说以前我们 ...
相关推荐
在maven中实现多环境的构建可移植性需要使用profile,通过不同的环境激活不同的profile来达到构建的可移植性。
使用maven Profile实现多环境构建,详细请参考 :http://blog.csdn.net/u011781521/article/details/77899467
maven-profile-2.0.6.jar!!!
maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装...
Maven 的41种骨架功能介绍,使用maven创建模板,能够更好的创建自己想要的项目结构
maven项目转换为eclipse项目,可能缺少的包。
Eclipse 安装maven的几种方式,以文档记录
NULL 博文链接:https://cjhz.iteye.com/blog/1721639
Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令Maven 命令
maven3.0maven3.0maven3.0maven3.0maven3.0maven3.0maven3.0maven3.0maven3.0maven3.0
主要介绍了使用maven profile指定配置文件打包适用多环境的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了maven profile动态选择配置文件详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
maven 工具 maven 工具 maven 工具 maven 工具 maven 工具
maven教程maven教程maven教程maven教程maven教程maven教程maven教程maven教程maven教程maven教程maven教程maven教程maven教程maven教程
Maven3.9.4版本压缩包,仅供学习参考,更新版本请前往Maven官方下载;Maven3.9.4版本压缩包,仅供学习参考,更新版本请前往Maven官方下载;Maven3.9.4版本压缩包,仅供学习参考,更新版本请前往Maven官方下载;Maven...
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,...于是希望有一种标准化的方式构建项目,一个清晰的方式定义项目的组成,一个容易的方式发布项目的信息,以及一种简单的方式在多个项目中共享JARs。
maven
maven api
maven-profile-2.1.0.jar
maven-profile-2.0.2.jar