blogSite

我是谁?我在哪儿?我在干什么?

View project on GitHub

Windows下本地Maven仓库配置


Maven下载与安装

  • Maven下载
    1. 点击Download进入下载页面
    2. 选择xxx-bin.zip下载
    3. 配置环境变量

      Path
      F:\soft\apache-maven-3.6.0\bin

  • 验证是否成功;进入maven的bin目录,如果配置了环境变量可在任意一目录下

    > mvn -v

  • 修改\conf\setting.xml配置文件;设置本地仓库位置,配置代理
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- 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>F:/Maven_Repo</localRepository>

  <proxies>
    <!-- 配置代理,如果有需要的话 -->
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <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>nextus-aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
    <mirror>
      <id>tortoisecloud</id>
      <mirrorOf>*</mirrorOf>
      <name>tortoisecloud</name>
      <url>http://mvnrepo.tortoisecloud.com:28081/repository/maven-public/</url>
    </mirror>
  </mirrors>

</settings>

验证配置是否正确> mvn help:system如果没有问题在”F:\Maven_Repo”下会下载很多文件

Maven从pom.xml下载jar到本地

  • 创建pom.xml文件
  • 进入cmd后,在pom.xml同级目录下运行语句> mvn dependency:copy-dependencies

添加jar到本地maven仓库

  • 使用命令> mvn install:install-file
    安装指定文件到本地仓库命令:mvn install:install-file
    -DgroupId=<groupId>       : 设置项目代码的包名(一般用组织名)
    -DartifactId=<artifactId> : 设置项目名或模块名 
    -Dversion=1.0.0           : 版本号
    -Dpackaging=jar           : 什么类型的文件(jar包)
    -Dfile=<myfile.jar>       : 指定jar文件路径与文件名(同目录只需文件名)
    安装命令实例:
    mvn install:install-file -DgroupId=com.baidu -DartifactId=ueditor -Dversion=1.0.0 -Dpackaging=jar -Dfile=ueditor-1.1.2.jar
    

PS

首页 > 学习总览 > 开发用插件 > Maven