1.依赖范围, 使用scope表示的。
scope的值有compile, test, provided ,默认是compile

scope:表示依赖使用的范围,也就是在maven构建项目的那些阶段中起作用。
maven构建项目:编译, 测试 ,打包, 安装 ,部署 过程(阶段)

 

 

例:
junit的依赖范围是 test

<dependencies>  <dependency>  <groupId>junit</groupId>  <artifactId>junit</artifactId>  <version>4.11</version>  <scope>test</scope>  </dependency>   <dependency>  <groupId>junit</groupId>  <artifactId>junit</artifactId>  <version>4.11</version>  <scope>provided</scope>  </dependency> </dependencies>


写好项目中的用到的所有依赖(jar ),必须在本地仓库中有。
没有必须通过maven下载, 包括provided的都必须下载。

你在servlet需要继承HttpServlet( provided) , 你使用的HttpServlet是maven仓库中的。

当你的写好的程序, 放到 tomat服务器中运行时, 此时你的程序中不包含servlet的jar
因为tomcat提供了 servlet的.jar

 

2.maven常用操作
maven的属性设置
    <properties> 设置maven的常用属性
maven的全局变量
自定义的属性:在<properties> 通过自定义标签声明变量(标签名就是变量名)
           在pom.xml文件中的其它位置,使用 ${标签名} 使用变量的值

自定义全局变量一般是定义依赖的版本号, 当你的项目中要使用多个相同的版本号,
先使用全局变量定义, 在使用${变量名}

例:

properties>  <spring.version>4.3.10.RELEASE</spring.version> </properties> <!--引用全局变量--> <dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-context</artifactId>  <version>${spring.version}</version> </dependency>


3.指定资源位置资源插件

src/main/java 和 src/test/java 这两个目录中的所有*.java 文件会分别在 comile 和 test-comiple 阶段被编译

编译结果分别放到了 target/classes 和 targe/test-classes 目录中;

但是这两个目录中的其他文件都会被忽略掉,如果需要把 src 目录下的文件包放到 target/classes 目录,作为输出的 jar 一部分。

那么需要指定资源文件位置。以下内容放到标签中。

<build>
    <resources>
      <resource>
        <directory>src/main/java</directory><!--所在的目录-->
        <includes><!--包括目录下的.properties,.xml 文件都会扫描到-->
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <!--filtering 选项 false 不启用过滤器, *.property 已经起到过滤的作用了 -->
        <filtering>false</filtering>
      </resource>
    </resources>
</build>

作用: 默认没有使用resources的时候, maven执行编译代码时, 会把src/main/resource目录中的文件拷贝到target/classes目录中。

4.Maven 系统采用的变量:

<properties>  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!--项目构建使用的编码,避免中文乱码--> <maven.compiler.source>1.8</maven.compiler.source><!--源码编译 jdk 版本--> <maven.compiler.target>1.8</maven.compiler.target><!--运行代码的 jdk 版本--> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><!--生成报告的编码--> </properties>