maven标签小笔记

本文详细介绍了Maven项目配置文件(pom.xml)的结构及关键元素的用途, 包括父项目的引用、依赖管理、资源文件过滤等特性,并展示了如何通过配置profiles来适应不同环境的需求。


<project 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/maven-v4_0_0.xsd">
    
    <!--父项目的相关信息-->
    <parent>
        <!--父项目的唯一标识符-->
        <artifactId>parentArtifactId</artifactId>
	<!--父项目的项目组织唯一标识符-->
<groupId>parentGroupId</groupId>
	<!--父项目的项目版本-->
<version>1.0-SNAPSHOT</version>
    </parent>
    <!--代表组织或整个项目的唯一标识符-->
<groupId>demoGroupId</groupId>
    <!--是一个项目描述符,描述这个pom文件遵从哪个版本-->
<modelVersion>4.0.0</modelVersion>
    <artifactId>demoArtifactId</artifactId>
    <packaging>war</packaging>
    <name>demo</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>com.demo.common</groupId>
            <artifactId>common-web</artifactId>
            <version>1.1.2</version>
	    <!--去掉某个模块-->
<exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.demo.common</groupId>
            <artifactId>common-struts</artifactId>
            <version>1.1.4-SNAPSHOT</version>
            <exclusions>
                <exclusion> 
                   <groupId>com.demo.common</groupId>
                    <artifactId>common-web</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
            </dependencies>
    <build>
        <finalName>demo</finalName>
        <resources>
            <resource>
		<!--指定该目录下的文件可用${}的形式读取-->
<directory>src/main/resources</directory>
		<!--过滤${}占位符,进而解析然后把pom文件中相应的属性(即profile中properties中的自定义标签)进行替换-->
<filtering>true</filtering>
            </resource>
        </resources>
    </build>
    <!--根据此标签配置不同的配置环境,如数据源有开发、测试环境,就可在此配置-->
<profiles>
        <profile>
	    <!--该profile的标识,必须写-->
<id>development</id>
	    <!--该profile的配置,可以不写-->
<properties>
		<!--自定义标签,写多少都行,都是你的配置,使用时用${}的形式获取,跟properties的读取方式一样-->
<demo.jdbc.driver>com.mysql.jdbc.Driver</demo.jdbc.driver>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <demo.jdbc.driver>com.mysql.jdbc.Driver</demo.jdbc.driver>
            </properties>
        </profile>
        <profile>
            <id>production</id>
            <properties>
                <cm.jdbc.driver>com.mysql.jdbc.Driver</cm.jdbc.driver>
            </properties>
        </profile>
    </profiles>
</project>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值