Maven基础
- Maven与Intellij IDEA的关系
Maven是Maven,Intellij IDEA是Intellij IDEA,两者是独立的,但是一般Intellij IDEA内嵌Maven。
1. 安装
- 安装地址
linux系统选择tar.gz安装包;windows选择zip包 - 下载完后,解压
- 修改配置文件
解压路径下有一个conf文件夹,打开settings.xml
找到
<localRepository>/path/to/local/repo</localRepository>
在其下面添加,其中xxxx是你电脑的某个文件夹,之后通过maven下载的java包都将放在该文件夹下
<localRepository>xxxx</localRepository>
在settings.xml中添加远程仓库,避免使用外国源下载速度慢
找到<mirrors></mirrors>,在其中间添加
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
- 添加环境变量
将解压路径/bin添加到系统环境变量,具体添加方式可以百度
2. 使用
- Intellij IDEA环境下

先配置好路径
File–>setting–>Build Tools --> Maven
配置好maven home directory(maven解压路径)、
user settings file(解压路径/conf/settings.xml)、local repository(之前配置的localRepository)
pom.xml
打开pom.xml,添加需要的依赖即可正常使用 - Maven
- 随便新建一个文件夹
- 在新建的文件夹下创建文件pom.xml
- 在pom.xml下添加需要安装的依赖
- 打开cmd,将路径切换到pom.xml文件所在的文件夹下,然后mvn install,即可正常使用
- 离线状态使用maven
完全离线状态使用maven是一件非常麻烦的事情,能力有限,暂时不懂。但是可以通过一台能上网的机器安装好依赖,然后复制到无网络状态的机器上。
具体步骤:
- 在可联网的及其上以上述maven的方式安装好依赖
- 在该机器下的localRepository路径下找到下载好的依赖
- 将依赖拷贝到无网络的机器上,粘贴路径为无网机器的localRepository
- Intellij IDA -->File–>setting–>Build Tools --> Maven 勾选离线模式work offline
- 如无法使用可重启idea或File–> Invalidate cache/restart或点击下图右侧maven下的刷新
