Maven的相关问题(一)——settings.xml配置详解
工作中第一次正式接触maven,虽然之前在学习时有遇到过,但是对于maven的认识和理解确实太浅薄,仅仅局限于机械式的操,纸上得来终觉浅,绝知此事要躬行···古人诚不欺我也~
下面先贴一个找到的一个非常详细的注解,链接:http://blog.csdn.net/mypop/article/details/6146686
1 <?xml version="1.0" encoding="UTF-8"?> 2 <settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 4 5 <localRepository>usr/local/mavenlocalRepository> 6 7 <interactiveMode>trueinteractiveMode> 8 9 <usePluginRegistry>falseusePluginRegistry> 10 11 <offline>falseoffline> 12 13 <pluginGroups> 14 15 <pluginGroup>org.codehaus.mojopluginGroup> 16 pluginGroups> 17 18 <proxies> 19 20 <proxy> 21 22 <id>myproxyid> 23 24 <active>trueactive> 25 26 <protocol>httpprotocol> 27 28 <host>proxy.somewhere.comhost> 29 30 <port>8080port> 31 32 <username>proxyuserusername> 33 34 <password>somepasswordpassword> 35 36 <nonProxyHosts>*.google.com|ibiblio.orgnonProxyHosts> 37 proxy> 38 proxies> 39 40 <servers> 41 42 <server> 43 44 <id>server001id> 45 46 <username>my_loginusername> 47 48 <password>my_passwordpassword> 49 50 <privateKey>${usr.home}/.ssh/id_dsaprivateKey> 51 52 <passphrase>some_passphrasepassphrase> 53 54 <filePermissions>664filePermissions> 55 56 <directoryPermissions>775directoryPermissions> 57 58 <configuration>configuration> 59 server> 60 servers> 61 62 <mirrors> 63 64 <mirror> 65 66 <id>planetmirror.comid> 67 68 <name>PlanetMirror Australianame> 69 70 <url>http://downloads.planetmirror.com/pub/maven2url> 71 72 <mirrorOf>centralmirrorOf> 73 mirror> 74 mirrors> 75 76 <profiles> 77 78 <profile> 79 80 <id>testid> 81 82 <activation> 83 84 <activeByDefault>falseactiveByDefault> 85 86 <jdk>1.5jdk> 87 88 <os> 89 90 <name>Windows XPname> 91 92 <family>Windowsfamily> 93 94 <arch>x86arch> 95 96 <version>5.1.2600version> 97 os> 98 99 <property> 100 101 <name>mavenVersionname> 102 103 <value>2.0.3value> 104 property> 105 106 <file> 107 108 <exists>/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/exists> 109 110 <missing>/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/missing> 111 file> 112 activation> 113 120 <properties> 121 <user.install>/ebs1/build-machine/usr/local/hudson/hudson-home/jobs/maven-guide-user.install> 122 properties> 123 124 <repositories> 125 126 <repository> 127 128 <id>codehausSnapshotsid> 129 130 <name>Codehaus Snapshotsname> 131 132 <releases> 133 134 <enabled>falseenabled> 135 136 <updatePolicy>alwaysupdatePolicy> 137 138 <checksumPolicy>warnchecksumPolicy> 139 releases> 140 141 <snapshots> 142 <enabled/><updatePolicy/><checksumPolicy/> 143 snapshots> 144 145 <url>http://snapshots.maven.codehaus.org/maven2url> 146 147 <layout>defaultlayout> 148 repository> 149 repositories> 150 151 <pluginRepositories> 152 153 <pluginRepository> 154 <releases> 155 <enabled/><updatePolicy/><checksumPolicy/> 156 releases> 157 <snapshots> 158 <enabled/><updatePolicy/><checksumPolicy/> 159 snapshots> 160 <id/><name/><url/><layout/> 161 pluginRepository> 162 pluginRepositories> 163 165 <activeProfiles> 166 167 <activeProfile>env-testactiveProfile> 168 activeProfiles> 169 profile> 170 profiles> 171 settings>settings.xml详解
下面是常用的几个标签,当然也是网上看的,链接:http://blog.csdn.net/Dynamic_W/article/details/77483311
localRepository标签用来指定本地资源库的路径,如果不修改,会默认在用户路径下新建一个.m2文件夹,下面的repository文件夹作为本地仓库,也就是在C盘,所以,项目用的jar包多了之后···
server标签用来做服务认证,如果搭建了私服,那么私服中的每个库都可以配单独的账号密码,更加细化权限的控制。这个server和下面的profile标签就是让我这个小白耽误了几天功夫的罪魁祸首。(不过也让我用好几天彻底搞清楚了maven,在eclipse中的配置,以及maven的作用,还好时间充裕···)
<server> <id>crm_Groupid> <username>adminusername> <password>admin123password> server>
profile标签为maven构件,每个构件有唯一的id,一个settings.xml文件可以存在多个构件,但构件只有被激活才能使用。当构件被激活的时候,该构件会替换maven项目中pom.xml文件中的同id的profile标签。
profile标签下的repositories标签为资源库标签,可以存在多个reposotory标签,即多个资源库。且资源库是立即生效的。
构件激活后,maven会优先去构件中的仓库找依赖,如果没有再去中央仓库找(当然,最开始还是先从本地仓库找)
<profile> <id>nexuesProfileid> <repositories> <repository> <id>crm_Groupid> <name>crm_groupname> <url>http://192.168.2.190/nexus/content/groups/crm_group/url> <snapshots> <enabled>trueenabled> snapshots> <releases> <enabled>trueenabled> releases> repository> repositories> profile>
mirror标签为镜像,当你本机访问中央库速度非常慢或者公司无法上网时需要使用自己的私服,那么配置一个镜像,maven就不会再去访问中央库而是访问你配置的镜像地址。
注意:配置镜像后,当需要的jar包在镜像中没有时,maven也不会再去访问中央库而是直接报错。
这个是用的比较多的,毕竟都是墙里的人类,国内靠谱的镜像还是挺多的,就不举例了,如果单位不能上外网或者有权限啥的,那应该有自己的私服或者有上中央库的权限的···