pom文件小记

来源:互联网 发布:淘宝店铺的运营管理 编辑:程序博客网 时间:2024/06/05 17:02

Maven的一个哲学是惯例优于配置(Convention Over Configuration)

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    <!-- Pom的版本号 -->    <modelVersion>4.0.0</modelVersion><!--    一个Maven坐标是一个地址,即“空间”里的某个点:从一般到特殊。当一个项目通过依赖,插件或者父项目引用和另外一个项目关联的时候,Maven通过坐标来精确定位一个项目。    比如下面依赖的servlet,它包含了一个对 avax.servlet:servlet-api:jar:2.5的依赖。    Maven坐标表示: groupId:artifactId:packaging:version    本例子中即为:com.hpu:test:war:0.0.1-SNAPSHOTgroupId:组织域名的倒转写法artifactId:项目的名字,在 groupId 下的表示一个单独项目的唯一标识符。packaging:打包格式(jar,war,apk等)version:一个项目的特定版本。“SNAPSHOT”标记表示正在开发。-->    <groupId>com.hpu</groupId>    <artifactId>test</artifactId>    <version>0.0.1-SNAPSHOT</version>    <packaging>war</packaging>    <description>test</description>    <organization>        <name>xiao, Inc.</name>        <url>http://www.hpu.edu.cn</url>    </organization>    <!-- 属性配置,这些配置供下面使用-->     <properties>    <!--定义项目的编码格式-->          <encoding>UTF-8</encoding>          <maven.compiler.source>1.6</maven.compiler.source>            <maven.compiler.target>1.6</maven.compiler.target>            <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>            <maven.tomcat.uriEncoding>UTF-8</maven.tomcat.uriEncoding>                <!-- 比如配置servlet的版本为2.5 ,在下面的依赖中直接${servlet.api.version},好处:方便版本的修改-->        <servlet.api.version>2.5</servlet.api.version>    </properties>    <!-- 项目所需的依赖 -->    <dependencies>               <!-- servlet -->               <dependency>                  <groupId>javax.servlet</groupId>                  <artifactId>servlet-api</artifactId>                  <version>${servlet.api.version}</version><!-- <scope>依赖范围: compile , test , provided,runtime,system配置:    默认为compile (编译范围):依赖的范围就是编译范    围。编译范围依赖在所有的classpath中可用,同时它们也会被打包。    provided(已提供范围):意味着打包的时候可以不用包进去,别的设施(Web Container)会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。相当于compile,但是在打包阶段做了exclude的动作。    test (测试范围):表示依赖项目仅仅参与测试相关的工作,包括测试代码的编译,执行。比较典型的如junit。    runtime(运行时范围):表示被依赖项目无需参与项目的编译,不过后期的测试和运行周期需要其参与。与compile相比,跳过编译而已。比如,你可能在编译的时候只需要JDBC API JAR,而只有在运行的时候才需要JDBC驱动实现。    system(系统范围):从参与度来说,也provided相同,不过被依赖项不会从maven仓库抓,而是从本地文件系统拿,一定需要配合systemPath属性使用。 -->                  <scope>provided</scope>               </dependency>            <dependency>                    <groupId>com.ibm</groupId>                    <artifactId>db2jcc</artifactId>                    <version>10.5.0</version>    <!-- <classifier>分类器的作用。将这个元素名在加在最后来查找相应的jar。比如这里有两个db2jcc -->              <classifier>db2jcc_license_cu</classifier>                </dependency>                <dependency>                    <groupId>com.ibm</groupId>                    <artifactId>db2jcc</artifactId>                    <version>10.5.0</version>                    <classifier>db2jcc</classifier>                </dependency>            <dependency>                    <groupId>org.webjars.npm</groupId>                    <artifactId>bootstrap-datepicker</artifactId>                    <version>1.6.0</version>                    <!-- 排除一些传递性依赖 -->                    <exclusions>                        <exclusion>                            <groupId>org.webjars.npm</groupId>                            <artifactId>jquery</artifactId>                        </exclusion>                        <exclusion>                            <groupId>org.webjars</groupId>                            <artifactId>bootstrap</artifactId>                        </exclusion>                    </exclusions>                </dependency>    </dependencies>    <!-- Build 节点配置的是项目编译的时候需要用到的一些东西。    resources: resource的列表,用于包括所有的资源    targetPath: 指定目标路径,用于放置资源,用于build    filtering: 是否替换资源中的属性placehold    directory: 资源所在的位置    includes: 样式,包括那些资源    excludes: 排除的资源    testResources: 测试资源列表-->    <build>        <resources>            <resource>                <directory>src/main/resources</directory>                <excludes>                    <!-- scss 在processsources阶段处理,无须拷贝这些资源 -->                    <exclude>**/*.scss</exclude>                </excludes>            </resource>        </resources>    <!-- 所需插件 -->        <plugins>            <!-- java 代码检查 -->            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-pmd-plugin</artifactId>                <version>3.6</version>                <executions>                    <execution>                        <phase>prepare-package</phase>                        <goals>                            <goal>check</goal>                        </goals>                    </execution>                </executions>            </plugin>     </build></project>
0 0
原创粉丝点击