有趣的网站之家,新品发布会视频,wordpress seo标题,东营网站app建设概述 Maven的settings.xml配置了Maven执行的方式#xff0c;像pom.xml一样#xff0c;但是它是一个通用的配置#xff0c;不能绑定到任何特殊的项目。它通常包括本地仓库地址#xff0c;远程仓库服务#xff0c;认证信息等。 settings.xml存在于两个位置#xff1a; mave… 概述 Maven的settings.xml配置了Maven执行的方式像pom.xml一样但是它是一个通用的配置不能绑定到任何特殊的项目。它通常包括本地仓库地址远程仓库服务认证信息等。 settings.xml存在于两个位置 maven目录下的/conf/settings.xml 用户目录下的/.m2/settings.xml maven目录下的称为全局配置用户目录下的称为用户配置。如果两个配置都存在它们的内容将合并有冲突的以用户配置优先。通常情况下用户目录下的/.m2/settings.xml是不存在的如果你需要可以从maven目录下的/conf/settings.xml复制过来。maven的默认settings模板中包含了所有的配置的例子它们都被注释掉了如果你需要可以打开注释配置你自己的信息。 下面是settings文件的顶层元素 settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsdlocalRepository/interactiveMode/usePluginRegistry/offline/pluginGroups/servers/mirrors/proxies/profiles/activeProfiles//settings settings文件中的内容可以使用插值替换例如: ${user.home}或者其他的系统属性3.0以上 ${env.HOME}等环境变量注意profile中定义的properties不能使用插值 详细设置 简单值simple value settings文件中顶层元素中的一半以上都是简单值。接下来让我们看一看吧。 settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsdlocalRepository${user.home}/.m2/repository/localRepositoryinteractiveModetrue/interactiveModeusePluginRegistryfalse/usePluginRegistryofflinefalse/offline...
/settings localRepository:本地仓库路径默认值为${user.home}/.m2/repository。它允许所有的用户从这个公共的本地仓库构建系统。interactiveMode默认为true代表maven是否可以和用户通过输入进行交互。usePluginRegistry默认为falsemaven是否可以使用${user.home}/.m2/plugin-registry.xml管理插件版本。从2.0以后我们是不需要使用这个属性的可以认为它废弃了。offline默认false构建系统是否可以使用离线模式。在不能连接远程仓库的情况下这个属性是非常有用的。插件组Plugin Groups pluginGroups包含了一组pluginGroup元素每一个都包含一个groupId。当你在命令行使用插件没有提供groupId时maven将搜索这个列表。列表默认包含org.apache.maven.plugins和org.codehaus.mojo。 settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsd...pluginGroupspluginGrouporg.mortbay.jetty/pluginGroup/pluginGroups...
/settings 例如我们执行org.mortbay.jetty:jetty-maven-plugin:run时可以使用短命令mvn jetty:run。 服务Servers 下载和部署的仓库通常在pom.xml中的repositories和distributionManagement元素中定义但是像username和password时不应该在单独的pom文件中定义这种配置信息应该在settings中定义。 settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsd...serversserveridserver001/idusernamemy_login/usernamepasswordmy_password/passwordprivateKey${user.home}/.ssh/id_dsa/privateKeypassphrasesome_passphrase/passphrasefilePermissions664/filePermissionsdirectoryPermissions775/directoryPermissionsconfiguration/configuration/server/servers...
/settings idserver的id它和maven连接的repository或mirror的id匹配。username, password用户名和密码这两个元素成对出现。privateKey, passphrase私钥文件和私钥密码也是成对出现。filePermissions, directoryPermissions当通过maven部署到远程仓库的时候文件和目录的权限通过这两个元素指定。当使用私钥文件的时候不要使用password要使用passphrase。 镜像Mirrors settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsd...mirrorsmirroridplanetmirror.com/idnamePlanetMirror Australia/nameurlhttp://downloads.planetmirror.com/pub/maven2/urlmirrorOfcentral/mirrorOf/mirror/mirrors...
/settings id, namemirror的唯一标识和用户设置的别名。当连接镜像需要用户名密码或私钥时id要和servers中配置的id一致。url镜像的url。构建系统时将使用这个地址而不是原始的仓库地址。mirrorOf仓库镜像的id。例如指向maven的中央仓库https://repo.maven.apache.org/maven2/设置为center。也可以使用一些高级的语法repo1,repo2 或 *,!inhouse。代理Proxies settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsd...proxiesproxyidmyproxy/idactivetrue/activeprotocolhttp/protocolhostproxy.somewhere.com/hostport8080/portusernameproxyuser/usernamepasswordsomepassword/passwordnonProxyHosts*.google.com|ibiblio.org/nonProxyHosts/proxy/proxies...
/settings idproxy的唯一标识。active代理是否有效。多个代理的情况下只能有一个代理有效。protocol, host, port代理的protocol://host:port分隔成了多个元素。username, password代理的用户名和密码成对出现。nonProxyHosts不使用代理的主机。使用逗号“,”分隔也可以。镜像和代理的区别镜像改变原始的仓库地址代理有些公司是不能上网的他们需要配置代理才能访问外网。 用户配置Profiles settings.xml文件中的profile是pom.xml中的删减版。它由activation, repositories, pluginRepositories 和 properties组成。而且只包含这4个元素因为settings中的是全局配置不是单个项目的配置。 如果settings中的profile是有效的它将覆盖掉pom中的相同id的profile。 激活Activation 它是profile中的一个元素会在满足activation的条件时激活状态。 settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsd...profilesprofileidtest/idactivationactiveByDefaultfalse/activeByDefaultjdk1.5/jdkosnameWindows XP/namefamilyWindows/familyarchx86/archversion5.1.2600/version/ospropertynamemavenVersion/namevalue2.0.3/value/propertyfileexists${basedir}/file2.properties/existsmissing${basedir}/file1.properties/missing/file/activation.../profile/profiles...
/settings 当activation的条件满足时该profile将激活。 jdkactivation有一个内嵌的在jdk元素中已java为中心的检查。当jdk的版本与配置的版本前缀匹配时这个profile将被激活。上面的例子中jdk的版本1.5.0_06将匹配。范围配置也是可以的这里不做详细介绍了。osos可以定义一些运行系统的特殊属性。由于比较少用不做过多介绍有兴趣的可以查阅官方文档。property如果maven探测到一个属性这个属性的值可以在pom.xml中配置它的值与配置的值匹配这个profile将被激活。上面的例子中mavenVersion2.0.3时profile将激活。fileexistence的文件存在或者missing的文件不存在条件将激活。activation不是profile激活的唯一方式settings.xml文件中的activeProfile元素包含了一个profile的id可以同过命令行指定这个id来激活profile。例如-P test将激活id为test的profile。 属性Properties maven的属性是一个占位符它可以在pom文件中通过${X}进行访问X是属性的名称。它们有5中不同的形式 env.X前缀是一个env它将返回系统的环境变量。例如${env.PATH}将返回系统的环境变量$path。 project.x访问pom嗯我那件点.在pom中代表层级的分隔。例如projectversion1.0/version/project可以通过${project.version}访问。 settings.x同上只是访问的是settings文件。例如settingsofflinefalse/offline/settings可以通过${settings.offline}访问。Java System Propertiesjava系统属性所有通过java.lang.System.getProperties()可以访问到的属性在pom文件中都可以访问。例如${java.home}。 xproperties元素里配置的属性。通过${someVal}访问。settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsd...profilesprofile...propertiesuser.install${user.home}/our-project/user.install/properties.../profile/profiles...
/settings 上面的例子中如果profile被激活在pom中可以访问${user.install}。 仓库Repositories Repositories在这里不是本地仓库的意思而是远程仓库的集合。它在本地仓库配置maven通过它从远程下载插件或者依赖。不同的仓库包含不同的项目在激活的profile下它们能被搜索到。 settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsd...profilesprofile...repositoriesrepositoryidcodehausSnapshots/idnameCodehaus Snapshots/namereleasesenabledfalse/enabledupdatePolicyalways/updatePolicychecksumPolicywarn/checksumPolicy/releasessnapshotsenabledtrue/enabledupdatePolicynever/updatePolicychecksumPolicyfail/checksumPolicy/snapshotsurlhttp://snapshots.maven.codehaus.org/maven2/urllayoutdefault/layout/repository/repositoriespluginRepositories.../pluginRepositories.../profile/profiles...
/settings releases, snapshots稳定版本或快照版本对应的配置。enabledtrue或者false。对应版本的仓库是否可用。updatePolicy更新策略。它指定了多长时间更新一次maven经常比较本地pom和远程pom的时间戳。它的选项有always、daily(默认)、interval:X(X是分钟)、never。checksumPolicy当maven部署文件到仓库时它还会部署相对应的checksum文件。选项有ignore, fail, 或 warn在checksum丢失或不正确的情况下执行。layout在上面的配置中它们都跟随一个公共的布局。这在大多数情况下是正确的。Maven 2有一个仓库的默认布局但是maven 1.x有一个不同的布局。使用这个元素可以选择使用哪个版本的布局default 或 legacy。插件仓库Plugin Repositories 仓库有两种主要的类型。第一种是工件作为依赖常说的jar包依赖。第二种是插件maven的插件是一种特殊类型的工件正因如此maven把插件类型的仓库单独提了出来。pluginRepositories的元素和repositories的元素非常的相似它指定一个远程插件仓库的地址可以在那里找到相应的maven插件。 激活profileActive Profiles settings xmlnshttp://maven.apache.org/SETTINGS/1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.0.0https://maven.apache.org/xsd/settings-1.0.0.xsd...activeProfilesactiveProfileenv-test/activeProfile/activeProfiles
/settings activeProfiles元素包含了activeProfile元素的集合activeProfile有一个profile的id值。在activeProfile里定义的id都将被激活。如果没有找到匹配的profile什么都不会生效。 好了maven的settings.xml就为大家介绍的这里有疑问可以随时评论、留言。接下来还会介绍maven的pom.xml。