突然想學maven,沒想到建項目的過程,就經歷的各種坑。。。
一開始建的是maven project,並且勾選了simple project,如圖:

很順利沒有任何問題,項目結構是這樣

看起來過於簡單,於是一番查詢后,開始進一步嘗試,選擇quickstart模板

報錯: Missing artifact junit:junit:jar:4.5
解決:Window——priferences——Myeclipse——Maven,將offline設置為不選,隨便在pom.xml按一下空格然后保存,它就可以自動下載jar文件了。。
接下來又嘗試了一下webapp模板,這回出現了很多問題

首先在右下角一直在加載Retrieving archetypes,導致特別卡,最后報錯,An internal error occurred during: "Retrieving archetypes:". GC overhead limit exceeded,大概的意思就是內存溢出,看了下任務管理器在加載的時候竟然達到一千多兆,查資料都很散,糾結了一整天。。
一種是修改myeclipse.ini文件,我的修改如下:

-Xms:JVM初始分配的內存 默認是物理內存的1/64
-Xmx:JVM最大分配的內存 默認是物理內存的1/4
-XX:最大非堆內存的大小,默認是物理內存的1/4
看到有高手總結優化MyEclipse速度的主要方法:
1.修改myeclipse.ini。
2.取消自動validation
3.勾掉無用插件。
4.修改啟動加載模塊
但是上面這種方法沒有改變我的問題
后來嘗試了一下不用myeclipse自帶的插件
解決:Window——priferences——Myeclipse——Maven——Archetypes

選擇Add Remote catalog,catalog file填寫:http://repo1.maven.org/maven2/archetype-catalog.xml
或者將archetype-catalog.xml 下載到本地,選擇Add Local catalog,填寫路徑,比聯網要快。。。然后點擊Apply->OK。
然后選擇我們新建的作為Catalog
剛剛接觸maven很多東西都是知其然不知其所以然,但是有一點是conf目錄下的setting.xml文件非常重要,里面設置了中央庫的位置,默認是在C:\Users\xxx\.m2\repository下,但是可以根據自己的需要修改,並且在window-preferences-MyEclipse-Maven4MyEclipse-User Setting里面的Local Repository與配置文件的位置保持一致
除此之外還有代理,鏡像,在下載jar文件時往往比較慢,是因為訪問國外的網站,可以在鏡像中做如下修改

<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
方法有一堆,但在我這並沒有起到太大的作用,換了工作空間也是如此,條條大路通羅馬,這次直接建web project,並選擇 Add maven
報了這樣一個錯,
Description Resource Path Location Type
Failure to transfer com.thoughtworks.xstream:xstream:pom:1.3.1 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact com.thoughtworks.xstream:xstream:pom:1.3.1 from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled. pom.xml /Test line 1 Maven Configuration Problem
直到現在也沒有解決,但意外的是,這個錯誤並沒有影響運行(希望有人可以告訴我這是怎么回事,一個紅叉叉,逼死強迫症啊)

測試一下,在pom.xml文件中加入如下代碼,
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
右下角可以看到正在下載對應的jar到我們的庫里

—————————————————————————————
—————————————————————————————
作為沒有經驗的新手,身邊沒有可以幫忙答疑的大神,只能一步一個坑的走了。。。
接下來要研究一下maven與一些主流框架的整合。。。
坑坑坑。。。
