zoukankan      html  css  js  c++  java
  • Maven的个性化定制

    用Maven的小伙伴都知道,Maven的宗旨是约定优于配置(Convention Over Configuration)。

    在宗旨的前提下Maven也提供了个性化定制的Profile,让我们看看使用方法哈!

    首先让我们一起看看Maven中的属性,这个用的挺多的:

    注:下面属性请在pom文件里使用。项目中使用默认是不支持的须要自己配置。

            内置属性: ${basedir}项目根文件夹

                              ${version} 项目版本

            Pom属性: ${project.artifactId}

                               ${project.build.sourceDirectory}

                               ${project.build.testSourceDirectory}

                               ${project.build.directory}

                               ${project.outputDirectory}

                               ${project.testOutputDirectory}

                               ${project.groupId}

                               ${project.version}

                               ${project.build.finalName}

            自己定义属性:Settings: ${settings.localRepository} 。引用settings.xml文件里的XML元素的值

            Java系统属性: ${user.home}

            环境变量属性: ${env.JAVA_HOME}


    如今我们開始认识Profile。下面是一个简单的Profile结构体:

    	<profiles>
    		<profile>
    			<id>dev</id>
    			<properties>
    				<db.driver>com.mysql.jdbc.Driver</db.dirver>
    			</properties>
    		</profile>
    	</profiles>

    定义一个id为dev、属性db.driver为com.mysql.jdbc.Driver的Profile。

    只定义即可了吗?答案是否定的。我们须要激活Profile才干生效,我们能够通过mvn clean install -P dev激活。

    (注:dev为激活ID,假设你想激活多个能够mvn clean install -P dev1,dev2使用,假设不想激活某一个用-P!dev1

    以上是一种激活方式,以下我们继续介绍其它激活方式

    activeByDefault默认激活

    	<profiles>
    		<profile>
    			<id>dev</id>
    			<properties>
    				<db.driver>com.mysql.jdbc.Driver</db.dirver>
    			</properties>
    			<activation>  
    				<activeByDefault>true</activeByDefault>  
    			</activation>  
    		</profile>
    	</profiles>
    settings.xml默认激活
    <settings>  
    ...  
    	<activeProfiles>  
    	    <activeProfile>dev1</activeProfile>  
    	</activeProfiles>  
    ...  
    </settings> 
    系统属性激活
    	<profiles>
    		<profile>
    			<id>dev</id>
    			<properties>
    				<db.driver>com.mysql.jdbc.Driver</db.dirver>
    			</properties>
    			<activation>  
    				<property>  
    				    <name>test</name>  
    				    <value>driver</value>
    				</property>
    			</activation>  
    		</profile>
    	</profiles>
    注:上面表示test=driver时才激活, mvn clean install -Dtest=driver

    系统环境激活

    	<profiles>
    		<profile>
    			<id>dev</id>
    			<properties>
    				<db.driver>com.mysql.jdbc.Driver</db.dirver>
    			</properties>
    			<activation>  
    				<jdk>[1.5,1.8)</jdk>
    				<file>   
    				    <missing>oracle.properties</missing>   
    				    <exists>jdbc.properties</exists>   
    				</file>
    			</activation>
    		</profile>
    	</profiles>
    注:上面表示jdk为1.5、1.6和1.7的时候激活

             存在jdbc.properties文件情况,不存在oracle.properties文件情况激活


    Profile种类等就不介绍了,用处不大。文章够长了,自己都看不下去了。

  • 相关阅读:
    Codeforces Beta Round #92 (Div. 2 Only) B. Permutations 模拟
    POJ 3281 Dining 最大流 Dinic算法
    POJ 2441 Arrange the BUlls 状压DP
    URAL 1152 Faise Mirrors 状压DP 简单题
    URAL 1039 Anniversary Party 树形DP 水题
    URAL 1018 Binary Apple Tree 树形DP 好题 经典
    pytorch中的forward前向传播机制
    .data()与.detach()的区别
    Argparse模块
    pytorch代码调试工具
  • 原文地址:https://www.cnblogs.com/llguanli/p/6771236.html
Copyright © 2011-2022 走看看