框架之maven总结1
Maven的核心
依赖管理 (不再需要拷贝jar包) -- 就是对jar包的管理
项目构建 项目再编码完成后,像项目进行编译、测试打包部署等一系列操作都可以通过命令来实现Maven安装、配置本地仓库
Maven安装、配置本地仓库
maven安装的前提条件:maven程序纯java开发,它的运行依赖jdk
1、maven的下载安装 apache-maven-3.5.4.zip --> 解压到本地磁盘 (不要有中文和空格)
(apache-maven-3.5.4.zip我上传到百度云https://pan.baidu.com/s/1oi7FaF0sJbIthOIzy5vJgA)
2、解压后各个目录的作用
bin-->可执行的本地命令 config-->配置文件 lib-->maven运行所需要的jar包 boot-->maven类加载器
3、配置环境变量 mvn -v 查询maven版本信息
3.1找到环境变量
3.2配置path到bin目录
(MAVEN_HOME的值就是apache-maven-3.5.4的绝对路径在这里我安装到D:\software\apache-maven-3.5.4)
3.3 配置本地仓库
上传到https://pan.baidu.com/s/1WyZu_SvI1m8qtGLqg-azhA
将repository放到电脑上的非中文目录就行(下图所示)
3.4修改 apache-maven-3.5.4目录下的conf下的settings.xml
增加本地仓库路径和阿里云镜像站配置
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!--配置本地仓库路径-->
<localRepository>D:\repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<!-- 阿里云镜像站配置 -->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
3.5命令行运行 mvn -v 证明是否安装成功
3.6有条件的可以配置私服和中央仓库
eclipse中关于maven的配置
首先apache-maven-3.5.4目录在我的电脑里面的绝对路径是D:\software\apache-maven-3.5.4
maven项目标准目录结构
src/main/java 主题程序源码
src/main/resources 项目所需要的配置文件
src/main/webapp 页面素材 (页面/css/js/image/jsp)
src/test -->单元测试类
maven的常用命令
都是在命令行里面运行 前面加 mvn
clean:清理 (将项目根目录下的target目录(类的字节码文件清理)删除掉) -->D:\mysoftware\eclipse32_workspace\chuanzhi-mybtis\target
compile:编译 (将项目中的.java文件编译为.class文件)
test: 单元测试 (将src/test/java目录下的所有的单元测试类进行测试) 前提:单元测试类名有要求(xxxxTest.java
package导包 (相当于 export war包 或者 jar包)
web project -- war包
java project -- jar包
将项目打包 打包项目再根目录下的target
install 将项目 经过 编译 单元测试 导包 然后在打包到本地仓库 (前面的操作都会执行)
maven项目的生命周期
在maven中存在"三套"生命周期,每一套生命周期都是相互独立的,互不影响的。
cleanLifeCycle:清理的生命周期
clean
defaultLifeCycle:默认生命周期
compile,test,package,install,deploy
siteLifeCycle:站点的生命周期
site
在maven项目的pom.xml添加jar包时的说明
group id:公司的名称 cn.itcast
artifact id:项目名称 01_helloWorld
version: 版本
packaging : 打包方式
依赖范围的注意事项
只要注意provided
对于运行时classpath有效 --》 表示运行部署到tomcat 比如servlet.api本来tomcat就有然后又部署到tomcat tomcat运行时就不知道要运行哪一个servlet.api。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>