maven如何配置?(图解)
maven是一个很大的库,里面有很多的依赖,现在一般都会用maven去创建项目。
配置maven;
下载对应的版本
maven下载地址
选中如下图的选项
解压到本地,并在同级目录新建一个文件夹用来放下载的依赖
配置仓库的路径
打开配置文件
因为国内的镜像太慢了,下面这个是阿里的,你可以直接把settings.xml全部改成下面的代码(最好去网上找最新的)
<?xmlversion="1.0"encoding="UTF-8"?><!--LicensedtotheApacheSoftwareFoundation(ASF)underoneormorecontributorlicenseagreements.SeetheNOTICEfiledistributedwiththisworkforadditionalinformationregardingcopyrightownership.TheASFlicensesthisfiletoyouundertheApacheLicense,Version2.0(the"License");youmaynotusethisfileexceptincompliancewiththeLicense.YoumayobtainacopyoftheLicenseathttp://www.apache.org/licenses/LICENSE-2.0Unlessrequiredbyapplicablelaworagreedtoinwriting,softwaredistributedundertheLicenseisdistributedonan"ASIS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.SeetheLicenseforthespecificlanguagegoverningpermissionsandlimitationsundertheLicense.--><!--|ThisistheconfigurationfileforMaven.Itcanbespecifiedattwolevels:||1.UserLevel.Thissettings.xmlfileprovidesconfigurationforasingleuser,|andisnormallyprovidedin${user.home}/.m2/settings.xml.||NOTE:ThislocationcanbeoverriddenwiththeCLIoption:||-s/path/to/user/settings.xml||2.GlobalLevel.Thissettings.xmlfileprovidesconfigurationforallMaven|usersonamachine(assumingthey'reallusingthesameMaven|installation).It'snormallyprovidedin|${maven.conf}/settings.xml.||NOTE:ThislocationcanbeoverriddenwiththeCLIoption:||-gs/path/to/global/settings.xml||Thesectionsinthissamplefileareintendedtogiveyouarunningstartat|gettingthemostoutofyourMaveninstallation.Whereappropriate,thedefault|values(valuesusedwhenthesettingisnotspecified)areprovided.||--><settingsxmlns="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.0http://maven.apache.org/xsd/settings-1.0.0.xsd"><!--localRepository|Thepathtothelocalrepositorymavenwillusetostoreartifacts.||Default:${user.home}/.m2/repository<localRepository>/path/to/local/repo</localRepository>--><localRepository>E:\maven\LocalWareHouse</localRepository><!--interactiveMode|Thiswilldeterminewhethermavenpromptsyouwhenitneedsinput.Ifsettofalse,|mavenwilluseasensibledefaultvalue,perhapsbasedonsomeothersetting,for|theparameterinquestion.||Default:true<interactiveMode>true</interactiveMode>--><!--offline|Determineswhethermavenshouldattempttoconnecttothenetworkwhenexecutingabuild.|Thiswillhaveaneffectonartifactdownloads,artifactdeployment,andothers.||Default:false<offline>false</offline>--><!--pluginGroups|Thisisalistofadditionalgroupidentifiersthatwillbesearchedwhenresolvingpluginsbytheirprefix,i.e.|wheninvokingacommandlinelike"mvnprefix:goal".Mavenwillautomaticallyaddthegroupidentifiers|"org.apache.maven.plugins"and"org.codehaus.mojo"ifthesearenotalreadycontainedinthelist.|--><pluginGroups><!--pluginGroup|Specifiesafurthergroupidentifiertouseforpluginlookup.<pluginGroup>com.your.plugins</pluginGroup>--><pluginGroup>org.mortbay.jetty</pluginGroup></pluginGroups><!--proxies|Thisisalistofproxieswhichcanbeusedonthismachinetoconnecttothenetwork.|Unlessotherwisespecified(bysystempropertyorcommand-lineswitch),thefirstproxy|specificationinthislistmarkedasactivewillbeused.|--><proxies><!--proxy|Specificationforoneproxy,tobeusedinconnectingtothenetwork.|<proxy><id>optional</id><active>true</active><protocol>http</protocol><username>proxyuser</username><password>proxypass</password><host>proxy.host.net</host><port>80</port><nonProxyHosts>local.net|some.host.com</nonProxyHosts></proxy>--></proxies><!--servers|Thisisalistofauthenticationprofiles,keyedbytheserver-idusedwithinthesystem.|Authenticationprofilescanbeusedwhenevermavenmustmakeaconnectiontoaremoteserver.|--><servers><!--server|Specifiestheauthenticationinformationtousewhenconnectingtoaparticularserver,identifiedby|auniquenamewithinthesystem(referredtobythe'id'attributebelow).||NOTE:Youshouldeitherspecifyusername/passwordORprivateKey/passphrase,sincethesepairingsare|usedtogether.|<server><id>deploymentRepo</id><username>repouser</username><password>repopwd</password></server>--><!--Anothersample,usingkeystoauthenticate.<server><id>siteServer</id><privateKey>/path/to/private/key</privateKey><passphrase>optional;leaveemptyifnotused.</passphrase></server>--><server><id>releases</id><username>ali</username><password>ali</password></server><server><id>Snapshots</id><username>ali</username><password>ali</password></server></servers><!--mirrors|Thisisalistofmirrorstobeusedindownloadingartifactsfromremoterepositories.||Itworkslikethis:aPOMmaydeclarearepositorytouseinresolvingcertainartifacts.|However,thisrepositorymayhaveproblemswithheavytrafficattimes,sopeoplehavemirrored|ittoseveralplaces.||Thatrepositorydefinitionwillhaveauniqueid,sowecancreateamirrorreferenceforthat|repository,tobeusedasanalternatedownloadsite.Themirrorsitewillbethepreferred|serverforthatrepository.|--><mirrors><!--mirror|Specifiesarepositorymirrorsitetouseinsteadofagivenrepository.Therepositorythat|thismirrorserveshasanIDthatmatchesthemirrorOfelementofthismirror.IDsareused|forinheritanceanddirectlookuppurposes,andmustbeuniqueacrossthesetofmirrors.|<mirror><id>mirrorId</id><mirrorOf>repositoryId</mirrorOf><name>HumanReadableNameforthisMirror.</name><url>http://my.repository.com/repo/path</url></mirror>--><mirror><!--Thissendseverythingelseto/public--><id>nexus</id><mirrorOf>*</mirrorOf><url>http://maven.aliyun.com/nexus/content/groups/public/</url></mirror><mirror><!--Thisisusedtodirectthepublicsnapshotsrepointheprofilebelowovertoadifferentnexusgroup--><id>nexus-public-snapshots</id><mirrorOf>public-snapshots</mirrorOf><url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url></mirror></mirrors><!--profiles|Thisisalistofprofileswhichcanbeactivatedinavarietyofways,andwhichcanmodify|thebuildprocess.Profilesprovidedinthesettings.xmlareintendedtoprovidelocalmachine-|specificpathsandrepositorylocationswhichallowthebuildtoworkinthelocalenvironment.||Forexample,ifyouhaveanintegrationtestingplugin-likecactus-thatneedstoknowwhere|yourTomcatinstanceisinstalled,youcanprovideavariableheresuchthatthevariableis|dereferencedduringthebuildprocesstoconfigurethecactusplugin.||Asnotedabove,profilescanbeactivatedinavarietyofways.Oneway-theactiveProfiles|sectionofthisdocument(settings.xml)-willbediscussedlater.Anotherwayessentially|reliesonthedetectionofasystemproperty,eithermatchingaparticularvaluefortheproperty,|ormerelytestingitsexistence.ProfilescanalsobeactivatedbyJDKversionprefix,wherea|valueof'1.4'mightactivateaprofilewhenthebuildisexecutedonaJDKversionof'1.4.2_07'.|Finally,thelistofactiveprofilescanbespecifieddirectlyfromthecommandline.||NOTE:Forprofilesdefinedinthesettings.xml,youarerestrictedtospecifyingonlyartifact|repositories,pluginrepositories,andfree-formpropertiestobeusedasconfiguration|variablesforpluginsinthePOM.||--><profiles><!--profile|Specifiesasetofintroductionstothebuildprocess,tobeactivatedusingoneormoreofthe|mechanismsdescribedabove.Forinheritancepurposes,andtoactivateprofilesvia<activatedProfiles/>|orthecommandline,profileshavetohaveanIDthatisunique.||Anencouragedbestpracticeforprofileidentificationistouseaconsistentnamingconvention|forprofiles,suchas'env-dev','env-test','env-production','user-jdcasey','user-brett',etc.|Thiswillmakeitmoreintuitivetounderstandwhatthesetofintroducedprofilesisattempting|toaccomplish,particularlywhenyouonlyhavealistofprofileid'sfordebug.||ThisprofileexampleusestheJDKversiontotriggeractivation,andprovidesaJDK-specificrepo.<profile><id>jdk-1.4</id><activation><jdk>1.4</jdk></activation><repositories><repository><id>jdk14</id><name>RepositoryforJDK1.4builds</name><url>http://www.myhost.com/maven/jdk14</url><layout>default</layout><snapshotPolicy>always</snapshotPolicy></repository></repositories></profile>--><!--|Hereisanotherprofile,activatedbythesystemproperty'target-env'withavalueof'dev',|whichprovidesaspecificpathtotheTomcatinstance.Tousethis,yourpluginconfiguration|mighthypotheticallylooklike:||...|<plugin>|<groupId>org.myco.myplugins</groupId>|<artifactId>myplugin</artifactId>||<configuration>|<tomcatLocation>${tomcatPath}</tomcatLocation>|</configuration>|</plugin>|...||NOTE:Ifyoujustwantedtoinjectthisconfigurationwheneversomeoneset'target-env'to|anything,youcouldjustleaveoffthe<value/>insidetheactivation-property.|<profile><id>env-dev</id><activation><property><name>target-env</name><value>dev</value></property></activation><properties><tomcatPath>/path/to/tomcat/instance</tomcatPath></properties></profile>--><profile><id>development</id><repositories><repository><id>central</id><url>http://central</url><releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>central</id><url>http://central</url><releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></pluginRepository></pluginRepositories></profile><profile><!--thisprofilewillallowsnapshotstobesearchedwhenactivated--><id>public-snapshots</id><repositories><repository><id>public-snapshots</id><url>http://public-snapshots</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>public-snapshots</id><url>http://public-snapshots</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></pluginRepository></pluginRepositories></profile></profiles><!--activeProfiles|Listofprofilesthatareactiveforallbuilds.|<activeProfiles><activeProfile>alwaysActiveProfile</activeProfile><activeProfile>anotherAlwaysActiveProfile</activeProfile></activeProfiles>--><activeProfiles><activeProfile>development</activeProfile><activeProfile>public-snapshots</activeProfile></activeProfiles></settings>
5.更改电脑的配置环境
新添加一个M2_HOME的系统变量 值设为 你的maven的解压路径
更改Path系统变量 新添加一个 %M2_HOME\bin% 的值
在命令行输入mvn -version 就可以看到maven安装的版本了
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。