Maven環境搭建

安裝

下載Maven,直接解壓F:\Java\apache-maven-3.2.3(可自定義文件解壓位置),即可完成安裝

配置環境變量

1.電腦->屬性>高級系統設置>環境變量

2.添加MAVEN_HOME=F:\Java\apache-maven-3.2.3

3.修改PATH,在配置中添加%MAVEN_HOME%\bin;

4.cmd種輸入:mvn –version,出現如下界面,表示安裝成功:


設置配置文件

Setting.xml文件是Maven中最重要的配置文件,默認位置:

%MAVEN_HOME%\conf\settings.xml

1.全局setting.xml

位於%MAVEN_HOME%\conf\settings.xml中,在該文件中配置的任何選項對於使用maven的所有應用程序均會產生影響,且賦予的影響力最大。該文件如果不做任何修改,第一次啓動Maven時,會在當前用戶的文件夾下建立一個.m2的文件夾,其中存放了maven本地倉庫的所有jar。

2.用戶setting.xml文件

拷貝%MAVEN_HOME%\conf\settings.xml文件到當前系統用戶文件下的\.m2\下的setting.xml文件,並在其中修改爲自定義的maven倉庫存放位置(用戶setting.xml並非一開始就有,它的出現在不修改maven全局配置的情況下,更加合理的配置用戶自己的maven配置文件)

<localRepository>F:/Java/apache-maven-3.2.3/repository</localRepository>

3.自定義setting.xml文件

拷貝%MAVEN_HOME%\conf\settings.xml文件到當前自定義用戶自定義的maven本地倉庫存放位置的同級目錄下,(自定義setting.xml同用戶setting.xml一樣,它的出現也是爲了更加合理的使用maven的配置文件):

<?xml version="1.0" encoding="UTF-8"?>
<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>D:/Java/maven2/Response</localRepository>-->
	<localRepository>F:/Java/apache-maven-3.2.3/repository</localRepository>
	<!--私服的驗證信息-->
	<servers>
		<server><!--設置發佈jar包時的用戶名及密碼-->
			<id>releases</id>
			<username>admin</username>
			<password>admin123</password>
		</server>		
		<server>
			<id>snapshots</id>
			<username>admin</username>
			<password>admin123</password>
		</server>
	</servers>
	<!--maven對全部倉庫的訪問全部攔截到私服的public倉庫中去,如果私服關閉,那麼就不能訪問中央工廠了-->
	<mirrors>
		<mirror><!--設置maven的遠程倉庫-->
			<id>nexus</id>
			<mirrorOf>*</mirrorOf>
			<name>Local Repository</name>
			  <url>http://localhost:8081/nexus/content/groups/public</url>
		</mirror>
	</mirrors> 
	<!--配置倉庫的一些信息,其主要作用是用來覆寫central中央倉庫的一些配置信息-->
	<profiles>
		<profile><!--設置central的路徑等-->
			<id>central</id>
			<repositories>
				<repository>
					<id>central</id>
					<name>Central</name>
					<!-- 該 url 沒有意義,可以隨便寫,但必須有。 -->
					<url>http://*</url>
					<releases><enabled>true</enabled></releases>
					<snapshots><enabled>true</enabled></snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>central</id>
					<name>local private nexus</name>
					<url>http://localhost:8081/nexus/content/groups/public</url>
					<releases><enabled>true</enabled></releases>
					<snapshots><enabled>true</enabled></snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
	<!--激活central-->
	<activeProfiles>
		<activeProfile>central</activeProfile>
	</activeProfiles>
</settings>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章