目录
一.Maven
1.什么是Maven?
Maven是专门用于管理和构建
Java项目的工具
,它的主要功能有:
提供了一套标准化的项目结构
提供了一套标准化的构建流程(编译,测试,打包,发布……)
提供了一套依赖管理机制
1.1 标准化的项目结构:
项目结构我们都知道,每一个开发工具(
IDE)都有自己不同的项目结构,它们互相之
间不通用。我再eclipse中创建的目录,无法在idea中进行使用,这就造成了很大的不方
便,如下图:前两个是以后开发经常使用的开发工具
1.2 标准化的构建流程:
1.3 依赖管理:
依赖管理其实就是管理你项目所依赖的第三方资源(
jar包、插件)。如之前我们项目中
需要使用JDBC和Druid的话,就需要去网上下载对应的依赖包
1.4依赖包资源网站
https://mvnrepository.com/artifact/com.mchange/c3p0/0.9.5.5
2.仓库
依赖jar包是存储在我们的本地仓库中。而项
目运行时从本地仓库中拿需要的依赖jar包。
2.1仓库分类:
本地仓库:自己计算机上的一个目录
中央仓库:由Maven团队维护的全球唯一的仓库
地址:
https://repo1.maven.org/maven2/
远程仓库(私服):一般由公司团队搭建的私有仓库
3.操作步骤
1.
2.
3.
如果引入依赖包后爆红色字体可以点击上图的刷新下载依赖包
<dependency> <groupId>mysql-java</groupId> <artifactId>mysql-java</artifactId> <version>5.1.21</version> </dependency>
如果需要找其他包可以参考这个网站1.4
https://mvnrepository.com/artifact/com.mchange/c3p0/0.9.5.5
4.鼠标右键点击pom.xml空白处然后找到Maven打开settings.xml
5.在settings.xml插入这串代码
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.conf}/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user