3.setting文件
maven配置文件顶级元素:
<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/> <interactiveMode/> <usePluginRegistry/> <offline/> <pluginGroups/> <servers/> <mirrors/> <proxies/> <profiles/> <activeProfiles/> </settings>
localRepository:指定了本地仓库地址,默认为 ${user.home}/.m2/repository
interactiveMode:TRUE,允许maven和用户交互,false不允许。默认为trueusePluginRegistry:true 指定maven使用 ${user.home}/.m2/plugin-registry.xml文件去管理插件版本。默认false,因为当前主流的maven2.0版本该文件不可靠。
offline:true,限制maven只能使用本地仓库构建项目。默认false。
pluginGroups:配置maven使用的插件的groupId。例如使用mvn jetty:run 由于没有指定jetty的groupId,但是实际上使用了jetty那么maven就去搜索pluginGroups下配置的所有groupId。
使用jetty可以如此配置<pluginGroups> <pluginGroup>org.mortbay.jetty</pluginGroup> </pluginGroups>备注:默认 org.apache.maven.plugins 和 org.codehaus.mojo两个groupId是包含在配置内的,不需要显示配置。
servers:我们可以通过pom文件配置资源。但是有些资源,例如连接的服务器账号密码是不能放在pom文件中的。所以需要与pom文件分开,setting文件中的servers标签就是这个用途。
<servers> <server> <id>server001</id> <username>my_login</username> <password>my_password</password> <privateKey>${user.home}/.ssh/id_dsa</privateKey> <passphrase>some_passphrase</passphrase> <filePermissions>664</filePermissions> <directoryPermissions>775</directoryPermissions> <configuration></configuration> </server> </servers>id:maven视图连接到的资源库或者镜像idfilePermissions,directoryPermissions:文件和目录权限,和unix一样使用三位数字。
mirrors:配置资源库镜像<mirrors> <mirror> <id>planetmirror.com</id> <name>PlanetMirror Australia</name> <url>http://downloads.planetmirror.com/pub/maven2</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors>id:和server中id对应name:随便取一个名字url:mirror的地址mirrorOf:与代理配合使用,可以指定为*,repo,repo1等,默认为central。proxies:设置请求代理,可以配置多个代理,但是同一时间只能有一个是激活的。<proxies> <proxy> <id>myproxy</id> <active>true</active> <protocol>http</protocol> <host>proxy.somewhere.com</host> <port>8080</port> <username>proxyuser</username> <password>somepassword</password> <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts> </proxy> </proxies>active:该代理是否激活nonProxyHosts:该元素下地址不使用代理
profiles:profile是pom.xml文件中profile元素的精简版。用来对整个系统进行配置,而不是针对具体的项目。setting中的profile如果和pom中id一样,那么将会覆盖pom中的profile<profiles> <profile> <id>test</id> <activation> <activeByDefault>false</activeByDefault> <jdk>1.5</jdk> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> <property> <name>mavenVersion</name> <value>2.0.3</value> </property> <file> <exists>${basedir}/file2.properties</exists> <missing>${basedir}/file1.properties</missing> </file> </activation> ... </profile> </profiles>activation:元素指定的所有条件被满足,该profile才会被启用。