Contents
26.1. Maven基础¶
26.1.1. 1.安装Maven¶
https://maven.apache.org
从Maven官网下载最新的Maven安装包,设置环境变量如下:
M2_HOME=/path/to/maven-3.6.x
PATH=$PATH:$M2_HOME/bin
Windows可以把%M2_HOME%\bin添加到系统Path变量中。
查看Maven版本信息:
C:\Users\18793> mvn -version
了解Maven安装目录结构¶
*bin:含有mvn运行的脚本
*boot:含有plexus-classworlds类加载器框架
*conf:含有settings.xml配置文件
*lib:含有Maven运行时所需要的java类库
*LICENSE.txt, NOTICE.txt, README.txt针对Maven版本,第三方软件等简要介绍
26.1.2. 2、修改从Maven中心仓库下载到本地的jar包的默认存储位置¶
从Maven中心仓库下载到本地的jar包的默认存放在“~/.m2/repository”中。
我们希望能够自己定义下载下来的jar包的存放位置,因此我们可以自己设置下载到本地时的jar包的存放目录。
settings.xml文件
增加如下配置,重启Eclipse生效:
<localRepository>D:\ProgramFiles\mvn\</localRepository>
如果习惯于在项目的lib目录下找jar包,
那么我们只需要在pom.xml中最后加上以下代码:
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${basedir}/src/main/webapp/WEB-INF/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>ib_terminal_server</finalName>
</build>
26.1.3. 3.配置远程中央仓库¶
一般情况下可以配置为国外的远程中央仓库,但是在国内从国外远程中央仓库下载jar包的速度比较差。 如果国内的话,建议使用阿里的远程中央仓库(下载速度快)。配置阿里的远程中央仓库
配置方式:
conf\setting.xml
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
中国区用户可以使用阿里云提供的Maven镜像仓库。使用Maven镜像仓库需要一个配置, 在用户主目录下进入.m2目录,创建一个settings.xml配置文件,内容如下:
<settings>
<mirrors>
<mirror>
<id>aliyun</id>
<name>aliyun</name>
<mirrorOf>central</mirrorOf>
<!-- 国内推荐阿里云的Maven镜像 -->
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
</settings>
26.1.4. 4. jar相关库文件下载地址¶
https://mvnrepository.com/
https://blog.csdn.net/u012851114/article/details/81872981
26.1.5. 5. 参考文献¶
https://blog.csdn.net/jakemanse/article/details/83035389
https://www.ctolib.com/topics-123587.html
https://blog.csdn.net/u012851114/article/details/81872981
https://www.cnblogs.com/weswes/p/9906871.html
https://blog.csdn.net/weixin_41433767/article/details/81783214
26.1.6. Intellij IDEA 往pom.xml 中添加maven依赖¶
打开pom.xml ——>在它里面右击选择generate (快捷键ALT+Insert) ——>点击dependency
26.1.7. 小结¶
Maven是一个Java项目的管理和构建工具:
- Maven使用pom.xml定义项目内容,并使用预设的目录结构;
- 在Maven中声明一个依赖项可以自动下载并导入classpath;
- Maven使用groupId,artifactId和version唯一定位一个依赖。