码迷,mamicode.com
首页 > 其他好文 > 详细

Maven

时间:2017-04-30 10:58:53      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:冲突   url   set   apach   cst   sources   环境   div   启动   

maven安装

下载安装包,maven官网

配置环境变量

MAVEN_HOME = D:\hnisi\local\apache-maven-3.0.4

PATH=%PATH%;%MAVEN_HOME%\bin

MAVEN_OPTS = -Xms128m -Xmx512m

M2_HOME = D:\hnisi\local\apache-maven-3.0.4

maven依赖冲突

maven是最先声明原则来引用相应版本的jar,而gradle是最新版本原则。

首先要定位错误的jar包,在项目启动时加上vm参数-verbose:class,这时会打印类似如下信息:

[Loaded java.util.TaskQueue from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.util.TimerThread from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.util.Timer$1 from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded org.quartz.impl.StdScheduler from file:/Users/lilu/repository/org/quartz-scheduler/quartz/2.2.1/quartz-2.2.1.jar]
[Loaded java.util.Hashtable$KeySet from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded org.quartz.SchedulerMetaData from file:/Users/lilu/repository/org/quartz-scheduler/quartz/2.2.1/quartz-2.2.1.jar]
[Loaded java.util.TreeMap$NavigableSubMap from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.util.TreeMap$AscendingSubMap from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.util.TreeMap$NavigableSubMap$EntrySetView from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.util.TreeMap$AscendingSubMap$AscendingEntrySetView from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.util.TreeMap$NavigableSubMap$SubMapIterator from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.util.TreeMap$NavigableSubMap$SubMapEntryIterator from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded org.quartz.simpl.JobWrapper from file:/Users/lilu/repository/org/quartz-scheduler/quartz/2.2.1/quartz-2.2.1.jar]
[Loaded org.quartz.simpl.TriggerWrapper from file:/Users/lilu/repository/org/quartz-scheduler/quartz/2.2.1/quartz-2.2.1.jar]
[Loaded sun.util.locale.provider.TimeZoneNameUtility from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.util.locale.provider.TimeZoneNameProviderImpl from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.util.resources.TimeZoneNamesBundle from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.util.resources.TimeZoneNames from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.util.resources.en.TimeZoneNames_en from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.util.LinkedHashMap$LinkedKeySet from /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar]
group_1.testJob_1 运行在: Sun Apr 30 08:41:57 CST 2017
[Loaded org.quartz.DisallowConcurrentExecution from file:/Users/lilu/repository/org/quartz-scheduler/quartz/2.2.1/quartz-2.2.1.jar]
[Loaded org.quartz.utils.ClassUtils f

maven的pom.xml会显示或隐式的依赖类包,如果不想依赖某个类包,可以通过用exclusion排除之,如下:

<dependency>  
        <groupId>org.unitils</groupId>  
        <artifactId>unitils-testng</artifactId>  
        <version>${unitils.version}</version>  
        <scope>test</scope>  
        <exclusions>  
            <exclusion>  
                <artifactId>junit</artifactId>  
                <groupId>junit</groupId>  
            </exclusion>  
        </exclusions>  
</dependency>  

maven仓库

技术分享

maven仓库主要有两种:

  • remote repository:相当于公共的仓库,大家都能访问到,一般可以用URL的形式访问

  • local repository:存放在本地磁盘的一个文件夹,例如,windows上默认是C:\Users\{用户名}\.m2\repository目录

repository里存放的都是各种jar包和maven插件。当向仓库请求插件或依赖的时候,会先检查local repository,如果local repository有则直接返回,否则会向remote repository请求,并缓存到local repository。也可以把做的东西放到本地仓库,仅供本地使用;或上传到远程仓库,供大家使用。 

maven mirror:

mirror相当于一个拦截器,它会拦截maven对remote repository的相关请求,把请求里的remote repository地址,重定向到mirror里配置的地址。

通过以下图解:

技术分享没有配置mirror

技术分享配置mirror

此时,B Repository被称为A Repository的镜像。

如果仓库X可以提供仓库Y存储的所有内容,那么就可以认为X是Y的一个镜像。换句话说,任何一个可以从仓库Y获得的构件,都胡够从它的镜像中获取。

Maven

标签:冲突   url   set   apach   cst   sources   环境   div   启动   

原文地址:http://www.cnblogs.com/liluredhat/p/6725202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!