Maven - 解决Maven下载依赖包速度慢问题

通常我们会因为下载jar包速度缓慢而苦恼,这十分影响开发效率,以及程序员的心情,在IDE下载jar时,无法对IDE做任何动作,只能大眼对小眼。另外我用的是eclipse下载速度极慢,一个14kb的文件往往需要想下载好几分钟。一个项目下来,无数个jar包,不知道得浪费多长时间,下载jar速度慢究其原因就是因为很多资源都是国外的,我们下载一个小文件几乎就跨越了一个太平洋那么远,那么有什么方法可以让下载速度变快呢?

其实方法很简单:

maven是支持镜像的,
我们可以在${maven_home}的conf目录下的setting.xml文件中找到<mirrors></mirrors>标签

加入国内镜像(aliyun):

<mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
  </mirrors>

最新版(aliyun):

<mirror>  
    <id>nexus-aliyun</id>  
    <mirrorOf>central</mirrorOf>    
    <name>Nexus aliyun</name>  
    <url>https://maven.aliyun.com/repository/public</url>  
</mirror>

下面是一些常用的maven国内镜像:

<mirror>  
      <id>CN</id>    
      <name>OSChina Central</name>                                                                                                                           
      <url>http://maven.oschina.net/content/groups/public/</url>    
      <mirrorOf>central</mirrorOf>  
    </mirror>  
    <mirror>      
          <id>repo2</id>      
          <mirrorOf>central</mirrorOf>      
          <name>Human Readable Name for this Mirror.</name>      
          <url>http://repo2.maven.org/maven2/</url>      
    </mirror>      
    <mirror>      
          <id>net-cn</id>      
          <mirrorOf>central</mirrorOf>      
          <name>Human Readable Name for this Mirror.</name>      
          <url>http://maven.net.cn/content/groups/public/</url>       
    </mirror>      
    <mirror>      
          <id>ui</id>      
          <mirrorOf>central</mirrorOf>      
          <name>Human Readable Name for this Mirror.</name>      
         <url>http://uk.maven.org/maven2/</url>      
    </mirror>      
    <mirror>      
          <id>ibiblio</id>      
          <mirrorOf>central</mirrorOf>      
          <name>Human Readable Name for this Mirror.</name>      
         <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>      
    </mirror>      
    <mirror>      
          <id>jboss-public-repository-group</id>      
          <mirrorOf>central</mirrorOf>      
          <name>JBoss Public Repository Group</name>      
         <url>http://repository.jboss.org/nexus/content/groups/public</url>      
    </mirror>    
        
        
    <mirror>      
          <id>JBossJBPM</id>  
          <mirrorOf>central</mirrorOf>  
          <name>JBossJBPM Repository</name>  
          <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>  
    </mirror>  
         <mirror>      
          <id>antelink</id>  
          <mirrorOf>central</mirrorOf>  
          <name>antelink Repository</name>  
          <url>http://maven.antelink.com/content/repositories/central/</url>  
    </mirror>  
    <mirror>      
          <id>openkoala</id>  
          <mirrorOf>central</mirrorOf>  
          <name>openkoala Repository</name>  
          <url>http://nexus.openkoala.org/nexus/content/groups/Koala-release/</url>  
    </mirror>  
    <mirror>      
          <id>tmatesoft</id>  
          <mirrorOf>central</mirrorOf>  
          <name>tmatesoft Repository</name>  
          <url>http://maven.tmatesoft.com/content/groups/public/</url>  
    </mirror>  
    <mirror>      
          <id>mavensync</id>  
          <mirrorOf>central</mirrorOf>  
          <name>mavensync Repository</name>  
          <url>http://mavensync.zkoss.org/maven2/</url>  
    </mirror>



总结:因为很多资源都是国外的,我们下载一个小文件几乎就跨越了一个太平洋那么远,所以使用镜像能大大提高我们下载依赖jar文件的速度!!!👍👍👍

博主:点赞收藏的都是帅锅!!!💕💕💕

  • 17
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
maven-compiler-plugin是Maven的一个核心插件,它用于编译Java源代码。如果项目的源代码中使用了依赖jar,那么这些jar也需要被编译到项目中。 maven-compiler-plugin并不会自动将依赖jar到项目中,但是它可以通过配置参数来处理这些依赖jar。一般来说,可以在pom.xml文件中通过dependency元素来声明内部依赖jar,然后在maven-compiler-plugin的配置中添加classpath元素,将这些依赖jar加入到编译的classpath中。 以下是一个示例配置: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <classpath> <dependency> <groupId>com.example</groupId> <artifactId>dependency1</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>dependency2</artifactId> <version>1.0.0</version> </dependency> </classpath> </configuration> </plugin> </plugins> </build> ``` 在这个配置中,我们使用了maven-compiler-plugin插件,并在其配置中添加了classpath元素。classpath元素中含了两个内部依赖jar:dependency1和dependency2。这些jar将被添加到编译的classpath中,使得项目可以正确地编译并运行。 在实际使用中,你需要将dependency元素替换为实际的内部依赖,以及修改groupId、artifactId和version等参数。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值