maven创建项目配置文件_在Maven中建立配置文件

maven创建项目配置文件

Profile in maven is nothing but subset of elements which allows to customize builds for particular environment. Profiles are also portable for different build environments.

Maven中的Profile只是元素的子集,它允许为特定环境自定义构建。 配置文件还可以移植到不同的构建环境中。

Build environment basically means a specific environment set for production and development instances. When developers work on development phase, they are intend to use database from the production instance and for the production phase, the live database will be used.

构建环境基本上是指为生产和开发实例设置的特定环境。 当开发人员在开发阶段工作时,他们打算使用生产实例中的数据库,而在生产阶段,将使用实时数据库。

So, in order to configure these instances maven provides the feature of build profiles. Any no. of build profiles can be configured and also can override any other settings in the pom.xml

因此,为了配置这些实例,maven提供了构建配置文件的功能。 不行 可以配置构建概要文件,也可以覆盖pom.xml任何其他设置

These defined profiles have the ability to modify the pom.xml during the build time. I.e. to configure separate environments for development and production instances. Based on the parameters passed, the corresponding profiles are activated accordingly. E.g. profiles can be set for dev, test and production phases.

这些定义的配置文件可以在构建期间修改pom.xml。 即为开发和生产实例配置单独的环境。 基于传递的参数,相应的配置文件将相应激活。 例如,可以为开发,测试和生产阶段设置概要文件。

Maven:构建配置文件的类型 (Maven: Types of build profiles)

The below table shows the types of build profiles in Maven :

下表显示了Maven中的构建配置文件类型:

Build Profile TypeDefined in
Per projectpom.xml
Per User/DeveloperMaven settings.xml (%USER_HOME%/.m2/settings.xml)
GlobalMaven global settings.xml (%M2_HOME%/conf/settings.xml)
构建配置文件类型 定义于
每个项目 pom.xml
每个用户/开发人员 Maven settings.xml(%USER_HOME%/。m2 / settings.xml)
全球 Maven全局settings.xml(%M2_HOME%/ conf / settings.xml)

Maven:构建可移植性 (Maven: Build Portability)

As mentioned above, different environments can be set up based on the requirements for a given project. So, with this the portability of a given project can be secured and handled effectively.

如上所述,可以根据给定项目的要求设置不同的环境。 因此,可以确保并有效处理给定项目的可移植性。

Build portability can be defined as the ability of a project which can be compiled and deployed successfully across different set of environments which also involves the applying different environmental configurations for the same. Any portable project should always tend to work without any customization of any properties.

构建可移植性可以定义为项目的能力,可以在不同的环境集之间成功地编译和部署项目,这还涉及对同一环境应用不同的环境配置。 任何可移植项目都应始终在不对任何属性进行任何自定义的情况下工作。

And Any portable project will always eliminates the complexities and issues associated to contributing to a project.

而且任何便携式项目都将始终消除与为项目做出贡献相关的复杂性和问题。

Maven:激活配置文件 (Maven: Activating profiles)

Below are ways in which build profiles of maven can be activated or triggered :

以下是可以激活或触发Maven的构建配置文件的方式:

  • Explicitly using commands

    明确使用命令

  • Maven settings

    Maven设置

  • Based on environment variables

    根据环境变量

  • Operating system settings

    作业系统设定

  • Present/missing files

    当前/缺少文件

Maven:明确使用命令 (Maven: Explicitly using commands)

<profiles>
   <profile>
      <id>test</id>
      <build>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-antrun-plugin</artifactId>
               <version>1.1</version>
               <executions>
                  <execution>
                     <phase>test</phase>
                     <goals>
                        <goal>run</goal>
                     </goals>
                     <configuration>
                     <tasks>
                        <echo>Using app.test.properties</echo>
                        <copy file="src/main/resources/app.test.properties" 
                        	tofile="${project.build.outputDirectory}/env.properties"/>
                     </tasks>
                     </configuration>
                  </execution>
               </executions>
            </plugin>
         </plugins>
      </build>
   </profile>
</profiles>

Maven设置示例 (Maven Settings Example)

Following is a basic Maven settings example:

以下是基本的Maven设置示例:

<settings 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/xsd/settings-1.0.0.xsd">
   <mirrors>
      <mirror>
         <id>com.testorg.companyname</id>
         <name>Internal Artifactory Maven repository</name>
         <url>http://repo1.maven.org/maven2/</url>
         <mirrorOf>*</mirrorOf>
      </mirror>
   </mirrors>
   <activeProfiles>
      <activeProfile>test</activeProfile>
   </activeProfiles>
</settings>

基于环境变量 (Based on Environment Variables)

<profile>
   <id>test</id>
      <activation>
      <property>
         <name>env</name>
         <value>test</value>
      </property>
   </activation>
</profile>

作业系统设定 (Operating System Settings)

<profile>
   <id>test</id>
   <activation>
         <os>
         <name>Windows 7</name>
         <family>Windows</family>
         <arch>x86</arch>
         <version>5.1.2600</version>
         </os>
   </activation>
</profile>

当前/缺少文件 (Present/missing files)

<profile>
   <id>test</id>
   <activation><file>
         <missing>
            target/generated-sources/axistools/wsdl2java/com/orgname/group
         </missing>
      </file>
   </activation>
</profile>

翻译自: https://www.studytonight.com/maven/build-profiles-in-maven

maven创建项目配置文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值