轉自:http://9leg.com/maven/2015/02/01/why-is-mvn-archetype-generate-so-low.html
最近從IntelliJ Idea 14的Community版本切換到Ultimate。
問題出現
最近從IntelliJ Idea 14的Community版本切換到Ultimate,key是從網絡上下載的。安裝之后,在創建maven project時(使用了archetype),速度慢的令人不敢相信,從Idea的控制台可以看到信息停留在:
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) < generate-sources @ standalone-pom <<< [INFO] [INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom -- - [INFO] Generating project in Batch mode
重試了很多次,都在Generating project in Batch mode等待,但Idea的狀態欄顯示還在不停的運行,並沒有卡死,大約30分鍾之后,才完成項目的創建。
問題分析
為什么會等怎么久呢?我先用mvn原生的命令試了一次,
mvn archetype:generate -DgroupId=com.9leg.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
還是在Generating project in Batch mode等了很久,但排除了Idea的問題。接着加上 -X 命令,用於顯示debugInfo.
mvn -X archetype:generate -DgroupId=com.9leg.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
輸出信息如下:
[INFO] Generating project in Batch mode [DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml
看來是請求網絡上的catalog.xml文件,才導致速度很慢。直接復制了url用瀏覽器打開,速度也是超級慢,等了很久才打開。 看來問題就是出現在這里。
看來是請求網絡上的catalog.xml文件,才導致速度很慢。直接復制了url用瀏覽器打開,速度也是超級慢,等了很久才打開。 看來問題就是出現在這里。
問題解決
- 直接下載archetype-catalog.xml文件,放到本地的apache-maven目錄中。
- 在使用mvn archetype:generate命令時,加上-DarchetypeCatalog=local,以替換網絡上的catalog.xml。
好了,OK了!!!又可以愉快的建立maven工程了!!!淚奔了好久!!!
直接到
http://repo1.maven.org/maven2/archetype-catalog.xml上下載該文件放到自己本地。
題外話
我切換到eclipse,生成maven項目並且選用了骨架archetype,沒有任何問題。在eclipse中可以設置maven的archetype catalog,不管是本地的,還是遠程的catalog,都可以設置。 切換到Idea中,找了半天,搜索了半天,似乎沒有這個設置。只是可以在創建項目時,單獨的設置自定義的archetype,而不能設置整個archetype列表。有誰知道請告知,謝謝。