03 idea中创建maven
1.在idea中设置maven ,让idea和maven结合使用。
idea中内置了maven ,一般不使用内置的, 因为用内置修改maven的设置不方便。
使用自己安装的maven, 需要覆盖idea中的默认的设置。让idea指定maven安装位置等信息配置的入口
①:配置当前工程的设置, file--settings ---Build, Excution,Deployment--Build Tools
--Maven
Maven Home directory: maven的安装目录
User Settings File : 就是maven安装目录conf/setting.xml配置文件
Local Repository : 本机仓库的目录位置
--Build Tools--Maven--Runner
VM Options : archetypeCatalog=internal
JRE: 你项目的jdk
archetypeCatalog=internal , maven项目创建时,会联网下载模版文件,
比较大, 使用-DarchetypeCatalog=internal,不用下载, 创建maven项目速度快。
②:配置以后新建工程的设置, file--other settings--Settings for New Project
1依赖范围, 使用scope表示的。
scope的值有 compile, test, provided ,默认是compile
scope:表示依赖使用的范围,也就是在maven构建项目的那些阶段中起作用。
junit的依赖范围是 test
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>a</groupId>
<artifactId>b</artifactId> b.jar
<version>4.11</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version> servlet.jar
<scope>provided</scope> 提供者
</dependency>
你在写项目的中的用到的所有依赖(jar ) ,必须在本地仓库中有。
没有必须通过maven下载, 包括provided的都必须下载。
你在servlet需要继承HttpServlet( provided) , 你使用的HttpServlet是maven仓库中的。
当你的写好的程序, 放到 tomat服务器中运行时, 此时你的程序中不包含servlet的jar
因为tomcat提供了 servlet的.jar