温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

maven-profile

发布时间:2020-07-29 17:02:33 来源:网络 阅读:510 作者:乾坤刀 栏目:软件技术

profile的目的是什么?
在我们实际的开发过程中会有dev、test、product等环境,或则不同的操作OS。而它们可能需要的配置参数是不一样的,比如:数据库。通常的做法就是在切换环境的同时修改我们的代码或则同一个properties文件。基于此,maven2.0给开发提供了一个更好的选择,profiles就是用于不同环境构建不同的project.

profile可以配置的地方有哪些?

  • 项目中的pom.xml
  • 系统用户中的maven setting:%USER_HOME%/.m2/settings.xml
  • 全局的maven setting:(${maven.home}/conf/settings.xml)
  • 位于project basedir 中的profile descriptor:(profiles.xml)

profile配置不同的地方的作用是什么?
本质上分为两类:一种是maven setting,作用于所有的project,通常是将不影响project build的配置放在此类文件中。如:<repositories>、<pluginRepositories>、<properties>(可以通过通配符被pom中properties属性引用)。另一种则是pom.xml,作用于单个project或其子module,通常是将影响project build的参数配置在pom.xml中profile中,如:<resources>、<properites>。

profile的激活方式?

  • mvn 命令行 -P,如:
    mvn groupId:artifactId:goal -P profile-1,profile-2
  • settings.xml中的<activeProfiles>标签,如:
    
    <settings>
    ...
    <activeProfiles>
    <activeProfile>profile-1</activeProfile>
    </activeProfiles>
    ...
    </settings>
* 根据JDK环境(自动检测),如:

<profiles>
<profile>
<activation>
<jdk>1.4</jdk>
</activation>
...
</profile>
</profiles>

* 根据OS,如:

<profiles>
<profile>
<activation>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
</activation>
...
</profile>
</profiles>

* 根据<activation>中的<property>,并同时来命令行中指定参数:mvn groupId:artifactId:goal -Ddebug=false。如:

<profiles>
<profile>
<activation>
<property>
<name>debug</name>
</property>
</activation>
...
</profile>
</profiles>

* 根据<activation>中的<activeByDefault>自动激活,如:

<profiles>
<profile>
<id>profile-1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
...
</profile>
</profiles>

* 根据<activation>中的<file>,<exists>和<missing>,如:

<profiles>
<profile>
<activation>
<file>
<missing>target/generated-sources/axistools/wsdl2java/org/apache/maven</missing>
</file>
</activation>
...
</profile>
</profiles>



**pom.xml中的profile能修改哪些内容?**

* <repositories>
* <pluginRepositories>
* <dependencies>
* <plugins>
* <properties>(not actually available in the main POM, but used behind the scenes)
* <modules>
* <reporting>
* <dependencyManagement>
* <distributionManagement>
* a subset of the <build> element, which consists of:
      * <defaultGoal>
      * <resources>
      * <testResources>
      * <finalName>

**如何查看哪些profiles是生效的?**
 mvn help:active-profiles
 mvn help:active-profiles -P appserverConfig-dev
 mvn help:active-profiles -Denv=dev

参考文档:http://maven.apache.org/guides/introduction/introduction-to-profiles.html
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI