MAVEN配置镜像中的一些小心得

1、maven配置镜像有两种方式,一种是在settings.xml文件中配置,一种是针对具体的项目在pom.xml文件中配置。
2、在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>
</mirrors>
        ②配置多个镜像源
<!--在profiles节点中按照模板进行多个镜像源配置-->
<profiles>
    <profile>
      <id>aliyun</id> 
      <repositories>
        <repository>
          <id>aliyun</id> 
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 
          <releases>
            <enabled>true</enabled>
          </releases> 
          <snapshots>
            <enabled>true</enabled> 
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile> 
    <profile>
      <id>maven-central</id> 
      <repositories>
        <repository>
          <id>maven-central</id> 
          <url>http://central.maven.org/maven2/</url> 
          <releases>
            <enabled>true</enabled>
          </releases> 
          <snapshots>
            <enabled>true</enabled> 
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
<profiles>
<!--在activeprofiles中激活profiles中的配置-->
<activeProfiles>
    <activeProfile>aliyun</activeProfile>
    <activeProfile>maven-central</activeProfile>
</activeProfiles>
3、使用maven导入依赖,这里以使用maven中央仓库、导入pellet推理机为例
        ①maven导入jar包形式依赖分为组名、工件名、版本名
        <dependency>
            <groupId>com.github.ansell.pellet</groupId>
            <artifactId>pellet-jena</artifactId>
            <version>2.3.6-ansell</version>
        </dependency>
        ②maven导入pom文件形式依赖分为组名、工件名、版本名、依赖类型
        <dependency>
            <groupId>com.github.ansell.pellet</groupId>
            <artifactId>pellet-parent</artifactId>
            <version>2.3.2</version>
            <type>pom</type>
        </dependency>
        ③往往只知道自己需要什么依赖,而不知道依赖是什么类型,属于什么组织。一般在浏览器搜索可以找到依赖所属官网或GitHub链接判断组织,也可以在编译器中尝试拼写依赖名,通常会有提示。获取组名和工件名后,可以在maven官网Central Repository:查找该依赖,找到依赖后可以看到依赖类型。
例如:

 4、在项目中配置maven镜像
<project>
  ...
  <repositories>
    <repository>
      <id>central</id>
      <url>https://repo1.maven.org/maven2</url>
    </repository>
    <repository>
      <id>mirror1</id>
      <url>https://mirror1.example.com/maven2</url>
    </repository>
    <repository>
      <id>mirror2</id>
      <url>https://mirror2.example.com/maven2</url>
    </repository>
  </repositories>
  ...
</project>

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值