導航:首頁 > 文件管理 > maven全局配置文件win7

maven全局配置文件win7

發布時間:2023-03-12 06:05:40

⑴ 怎麼配置maven的settings

第一步:配置maven的庫
1、在本地新建一個文件夾,來存放maven需要的jar庫。如下圖所示:
2、修改maven配置文件settings.xml,D:\apache-maven-3.3.3\conf\settings.xm
第二步:eclipse配置maven
1、打開cclipse,依次打開Windows-->Prefrences,點擊Maven的右邊的三角符號,以展開Maven的配置界面
2、然後點擊Maven下面的Installations選項,出現如下界面,請點擊Add按鈕
3、再後請選擇您的maven安裝路徑,這里我的maven的安裝目錄為D:\apache-maven-3.3.3 ,選擇你的maven安裝目錄,並點擊確定, 之後可以點擊Apply,點擊OK
4、再然後點擊Maven下面的User Settings選項,點擊第二個Browse..按鈕,選擇第一步配置的maven配置文件settings.xml。然後點擊下面的Update Settings按鈕,再點擊下面的Apply按鈕,點擊ok就完成了

⑵ maven全局配置文件路徑為

conf/settings.xml文件。根據查詢maven全局配置的相關資料顯示,maven全局配置文件路徑為conf/settings.xml文件。Maven的全局配置文件是Maven安裝目錄conf/settings.xml文件,該文件可以配置倉庫、代理、profile、鏡像、插件等。

⑶ maven配置文件settings.xml中的profiles怎麼用

profile介紹


4.1profile簡介

profile可以讓我們定義一系列的配置信息,然後指定其激活條件。這樣我們就可以定義多個profile,然後每個profile對應不同的激活條件和配置信息,從而達到不同環境使用不同配置信息的效果。比如說,我們可以通過profile定義在jdk1.5以上使用一套配置信息,在jdk1.5以下使用另外一套配置信息;或者有時候我們可以通過操作系統的不同來使用不同的配置信息,比如windows下是一套信息,linux下又是另外一套信息,等等。具體的激活條件有哪些我在後文會講到。


4.2profile的定義位置

對於使用Maven3,我們可以有多個地方定義profile。定義的地方不同,它的作用范圍也不同。

針對於特定項目的profile配置我們可以定義在該項目的pom.xml中。

針對於特定用戶的profile配置,我們可以在用戶的settings.xml文件中定義profile。該文件在用戶家目錄下的「.m2」目錄下。

全局的profile配置。全局的profile是定義在Maven安裝目錄下的「conf/settings.xml」文件中的。


4.3profile中能定義的信息

profile中能夠定義的配置信息跟profile所處的位置是相關的。以下就分兩種情況來討論,一種是定義在settings.xml中,另一種是定義在pom.xml中。


4.3.1 profile定義在settings.xml中

當profile定義在settings.xml中時意味著該profile是全局的,它會對所有項目或者某一用戶的所有項目都產生作用。因為它是全局的,所以在settings.xml中只能定義一些相對而言范圍寬泛一點的配置信息,比如遠程倉庫等。而一些比較細致一點的需要根據項目的不同來定義的就需要定義在項目的pom.xml中。具體而言,能夠定義在settings.xml中的信息有<repositories>、<pluginRepositories>和<properties>。定義在<properties>裡面的鍵值對可以在pom.xml中使用。

4.3.2 profile定義在pom.xml中

定義在pom.xml中的profile可以定義更多的信息。主要有以下這些:

l<repositories>

l<pluginRepositories>

l<dependencies>

l<plugins>

l<properties>

l<dependencyManagement>

l<distributionManagement>

l還有build元素下面的子元素,主要包括:

<defaultGoal>

<resources>

<testResources>

<finalName>

4.4profile的激活方式

Maven給我們提供了多種不同的profile激活方式。比如我們可以使用-P參數顯示的激活一個profile,也可以根據環境條件的設置讓它自動激活等。下面將對它們一一進行介紹:

4.4.1 使用activeByDefault設置激活

先看下面一個配置

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<properties>

<hello>world</hello>

</properties>

<activation>

<activeByDefault>true</activeByDefault>

</activation>

</profile>

<profile>

<id>profileTest2</id>

<properties>

<hello>andy</hello>

</properties>

</profile>

</profiles>

我們可以在profile中的activation元素中指定激活條件,當沒有指定條件,然後指定activeByDefault為true的時候就表示當沒有指定其他profile為激活狀態時,該profile就默認會被激活。所以當我們調用mvn package的時候上面的profileTest1將會被激活,但是當我們使用mvn package –P profileTest2的時候將激活profileTest2,而這個時候profileTest1將不會被激活。

4.4.2 在settings.xml中使用activeProfiles指定處於激活狀態的profile

我們可以在settings.xml中使用activeProfiles來指定需要激活的profile,這種方式激活的profile將所有情況下都處於激活狀態。比如現在我們定義了如下兩個profile

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<properties>

<hello>world</hello>

</properties>

</profile>

<profile>

<id>profileTest2</id>

<properties>

<hello>andy</hello>

</properties>

</profile>

</profiles>

這里的profile可以是定義在settings.xml中的,也可以是定義在pom.xml中的。這個時候如果我們需要指定profileTest1為激活狀態,那麼我們就可以在settings.xml中定義activeProfiles,具體定義如下:

Xml代碼

<activeProfiles>

<activeProfile>profileTest1</activeProfile>

</activeProfiles>

考慮這樣一種情況,我們在activeProfiles下同時定義了多個需要激活的profile。這里還拿上面的profile定義來舉例,我們定義了同時激活profileTest1和profileTest2。

Xml代碼

<activeProfiles>

<activeProfile>profileTest1</activeProfile>

<activeProfile>profileTest2</activeProfile>

</activeProfiles>

從profileTest1和profileTest2我們可以看出它們共同定義了屬性hello。那麼這個時候我在pom.xml中使用屬性hello的時候,它到底取的哪個值呢?是根據activeProfile定義的順序,後面的覆蓋前面的嗎?根據我的測試,答案是非也,它是根據profile定義的先後順序來進行覆蓋取值的,然後後面定義的會覆蓋前面定義的。

4.4.3 使用-P參數顯示的激活一個profile

假設我們現在有如下定義的profiles

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<properties>

<hello>world</hello>

</properties>

</profile>

<profile>

<id>profileTest2</id>

<properties>

<hello>andy</hello>

</properties>

</profile>

<profiles>

那麼當我們在進行Maven操作時就可以使用-P參數顯示的指定當前激活的是哪一個profile了。比如我們需要在對項目進行打包的時候使用id為profileTest1的profile,我們就可以這樣做:

Cmd代碼

mvnpackage–PprofileTest1

當我們使用activeByDefault或settings.xml中定義了處於激活的profile,但是當我們在進行某些操作的時候又不想它處於激活狀態,這個時候我們可以這樣做:

Cmd代碼

Mvnpackage–P!profileTest1

這里假設profileTest1是在settings.xml中使用activeProfile標記的處於激活狀態的profile,那麼當我們使用「-P !profile」的時候就表示在當前操作中該profile將不處於激活狀態。

4.4.4根據環境來激活profile

profile一個非常重要的特性就是它可以根據不同的環境來激活,比如說根據操作系統的不同激活不同的profile,也可以根據jdk版本的不同激活不同的profile,等等。

4.4.4.1根據jdk來激活profile

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<jdk>1.5</jdk>

</profile>

<profiles>

上面情況表示在jdk為1.5版本系列的時候激活profileTest1。

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<jdk>[1.4,1.7)</jdk>

</profile>

<profiles>

上面的情況表示在jdk為1.4、1.5和1.6的時候激活profileTest1。

4.4.4.2根據操作系統來激活profile

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<activation>

<os>

<name>WindowsXP</name>

<family>Windows</family>

<arch>x86</arch>

<version>5.1.2600</version>

</os>

</activation>

</profile>

</profiles>

上面的情況就是根據操作系統的類型來激活profileTest1。

4.4.4.3根據系統屬性來激活profile

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<activation>

<property>

<name>hello</name>

<value>world</value>

</property>

</activation>

</profile>

</profiles>

上面的profileTest1將在提供了系統屬性hello,並且其值為world的時候激活。下面的做法可以激活profileTest1。

Cmd代碼

mvnpackage–Dhello=world

當是下面的這種定義形式時,profileTest1將在指定了系統屬性hello,且其值為任意值的時候被激活。

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<activation>

<property>

<name>hello</name>

</property>

</activation>

</profile>

</profiles>

4.4.4.4根據文件是否存在激活profile

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<activation>

<file>

<exists>target</exists>

</file>

</activation>

</profile>

</profiles>

上面的定義表示當存在target文件時激活profileTest1。

Xml代碼

<profiles>

<profile>

<id>profileTest1</id>

<activation>

<file>

<missing>target</missing>

</file>

</activation>

</profile>

</profiles>

上面的定義表示當不存在target文件時激活profileTest1。

4.5查看當前處於激活狀態的profile

我們可以同時定義多個profile,那麼在建立項目的過程中,到底激活的是哪一個profile呢?Maven為我們提供了一個指令可以查看當前處於激活狀態的profile都有哪些,這個指定就是mvn help:active-profiles。

現在假設我們的settings.xml文件中有如下profile的定義:


<profiles>

<profile>

<id>profileTest1</id>

<activation>

<file>

<missing>target</missing>

</file>

</activation>

</profile>

</profiles>

<activeProfiles>

<activeProfile>profileTest1</activeProfile>

</activeProfiles>

這個時候我們可以看到,我們已經定義了profileTest1始終為激活狀態,這個時候我們使用mvn help:active-profiles查看處於激活狀態的profile時,就會列印出如下內容:

⑷ weindows mvn 配置文件在哪兒

下載maven,下載後如果是壓縮包,進行解壓,得到maven目錄。

找到我們的maven目錄並復制路徑,右鍵計算機,屬性里選擇高級系統設置,找到環境變數。

用戶變數下選擇新建,變數名為M2_HOME,變數值為D:\Program Files\apache-maven-3.1.0,點擊確定

找到maven下的bin目錄D:\Program Files\apache-maven-3.1.0\bin復制,用戶變數下選中PATH點擊編輯,粘貼,注意加分號跟其它的隔開。

這就算配置完成,驗證對不對,win+R快捷鍵cmd進入dos窗口,輸入命令,mvn -v(注意中間有個空格),回車運行後可以看見maven版本maven home表示安裝成功。

進入或者新建想要生成項目的文件夾,通過運行dos命令mvn archetype:generate,可以簡單搭建一個maven項目的骨架。運行過程中會讓我們輸入groupId,artifactId,package,也可以直接設置這些,例如:mvn archetype:generate -DgroupId=com.xh.maven -DartifactId=maven_03 -Dversion=0.0.1_SNAPSHOT

如果我們寫好了一個項目,dos命令下可以通過mvn compile編譯項目src/main/java下中的類

如果編譯的結果顯示有ERROR,怎麼查看ERROR的詳細信息呢,可以通過mvn -e,從本例這個提示看,就是pom.xml上第一行xml後面編碼encoding拼寫錯誤

mvn項目是src下有個main,還有個test測試,mvn -test就是編譯src/test/java中的類

mvn package 打包
mvn install 會把打的jar包發到倉庫中,這樣另一個項目中pom.xml下通過dependency下配置就可調用裡面的類

⑸ eclipse 自帶maven 配置在哪

maven使用方法如下
下載解壓Maven包增加兩個環境變數
Path : 解壓目錄/bin
M2_HOME: 解壓目錄
驗證安裝:
開始->運行->cmd進入命令行窗口 Mvn -v
Eclipse中的Maven設置:
Window->preferences->maven->installation->add Maven的安裝目錄
Maven的配置文件
全局配置文件的位置: ${maven.home}/conf/settings.xml 需拷貝到用戶模式下
用戶配置文件的位置:${user.home}/.m2/settings.xml
Maven庫的設置:
Maven引用的jar包,都會通過網路下載添加到maven的庫中,方便下次調用,默認存放的庫是${user.home}/.m2/repository ,庫中的數據越會來月多,存放在C盤,隨著系統盤的格式化庫會丟失,所以需要自定義庫的位置。
下載一份包含較多jar包的maven庫文件(M2repository.zip),解壓並修改用戶(user)配置文件<localRepository>庫文件的目錄</localRepository>
也可以在Window->preferences->maven->user settings ->Local Repository中修改
使用Eclipse創建Maven項目:
File->new->other..àMaven->Maven project
創建jar項目,可以選擇使用maven-archetype-quickstart來創建
創建war項目,可以選擇使用cocoon-archetype-webapp來創建
接著填寫項目的坐標信息,maven使得項目更有層次性,利於管理

groupId:項目或者組織的唯一標志,並且配置時生成的路徑也是由此生成,如org.codehaus.mojo生成的相對路徑為:/org/codehaus/mojo
artifactId: 項目的通用名稱
version:項目的版本
packaging: 打包的機制,如pom, jar, maven-plugin, ejb, war, ear, rar, pa
希望能夠幫助你

閱讀全文

與maven全局配置文件win7相關的資料

熱點內容
maya粒子表達式教程 瀏覽:84
抖音小視頻如何掛app 瀏覽:283
cad怎麼設置替補文件 瀏覽:790
win10啟動文件是空的 瀏覽:397
jk網站有哪些 瀏覽:134
學編程和3d哪個更好 瀏覽:932
win10移動硬碟文件無法打開 瀏覽:385
文件名是亂碼還刪不掉 瀏覽:643
蘋果鍵盤怎麼打開任務管理器 瀏覽:437
手機桌面文件名字大全 瀏覽:334
tplink默認無線密碼是多少 瀏覽:33
ipaddgm文件 瀏覽:99
lua語言編程用哪個平台 瀏覽:272
政采雲如何導出pdf投標文件 瀏覽:529
php獲取postjson數據 瀏覽:551
javatimetask 瀏覽:16
編程的話要什麼證件 瀏覽:94
錢脈通微信多開 瀏覽:878
中學生學編程哪個培訓機構好 瀏覽:852
榮耀路由TV設置文件共享錯誤 瀏覽:525

友情鏈接