2. Maven的安装与配置

1. 配置maven环境变量

 

 配置maven时候,请先确保已经配置好JAVA_HOME, 只能是JAVA_HOME  

配置完成之后,cmd执行 mvn-v 即可查看

1. maven 配置的时候,bin 里面的settings 文件不能配置<localRepository>D:\maven\mvnRespo</localRepository>,要不然不会生成全局即c 盘的.m2,而是生成在制定的文件夹下
2. mvn help:system  生成.m2 文件夹,生成的是maven的依赖库

3. maven 必须依赖jdk ,而且环境变量中必须配置Java_HOME 这个环境变量

4. 在C 盘.m2 文件下设置settings.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>D:/developeTool/maven-house</localRepository>
<mirrors>
<mirror>
<id>central</id>
<mirrorOf>central</mirrorOf>
<name>Aliyun Mirror.</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>

<servers>
<server>
<id>dev-mirrors</id>
<username>admin</username>
<password>admin123</password>
</server>
    </servers>
</settings>

maven缺少依赖包,强制更新命令

mvn clean compile install -e -U 

-e详细异常,-U强制更新

maven安装好之后,可以查看默认的下载仓库远程地址:mvn help:system

而我们如果让其默认为Ali yun镜像下载地址,则可以修改settings.xml, pom.xml配置为

mirror-1mirror-2repository-1repositor-2result
    repo.maven.apache.org
 *      URL/M1    URL/M1
 M2   URL/M2  repo.maven.apache.org
 central  URL/C   URL/C
*      URL/M1 central  URL/C  central  URL/C
 *    URL/M1    R1   URL/R1 URL/M1
 *     URL/M1central  URL/CR1   URL/R1 URL/M1
R1    URL/M1central  URL/CR1   URL/R1 URL/M1   URL/C

 

pom.xml测试文件如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>cn.my</groupId>
	<artifactId>maven</artifactId>
	<version>4.0.2-SNAPSHOT</version>
	<packaging>pom</packaging>
	<name>maven-test</name>
   
    <dependencies>
      
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.4</version>
      </dependency>
      
        <!-- Swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
        <!-- End of Swagger -->
           
    </dependencies>
	
 
	<repositories>
		<repository>
			<id>RRR</id>
			<url>https://www.sogou.com/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>

</project>

settings.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>

 
    <localRepository>/root/maven_house </localRepository>

  <mirrors>
   
     <mirror>
          <id>A</id>
        <mirrorOf>central</mirrorOf>
          <name>AName</name>
          <url>http://localhost:6080</url>
       </mirror>
   
    <mirror>
           <id>A1</id>
         <mirrorOf>RRR</mirrorOf>
         <name>AName1</name>
           <url>http://localhost:6084</url>
      </mirror>
  </mirrors>
</settings>
 

 linux   maven  nexus(私服) 搭建

wget http://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.6.0-02-unix.tar.gz

解压、重命名

tar -zxvf nexus-3.6.0-02-unix.tar.gz  //解压
mv nexus-3.6.0-02  nexus              //重命名

 

1. Maven中的modelVersion指定了当前POM模型的版本,对于Maven2和Mave3来说,它只能是4.0.0

2.groupID: 定义了项目属于哪个组,这个组往往和项目所在的组织或公司存在关联。譬如在googlecode上建立了一个名为myapp的项目,那么groupId就应该是com.goolecode.myapp,如果你的公司是mycom,有一个项目为myapp,那么groupId就应该是com.mycom.myapp.

3.artifactId:当前项目在组中的唯一ID,一般为jar包名

4.version: 指定了当前的版本。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值