天天看點

maven-通過maven指令建立maven項目

這裡預設已經安裝好了Maven工具。可以通過在cmd打開的指令提示符中運作mvn -v 檢視安裝的maven資訊。

首先要注意mvn archetype:create 在maven3.0.X及以上版本運作時會報錯是以最好運用 mvn archetype:generate 建立maven項目

錯誤資訊類似以下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration

 of mojo org.apache.maven.plugins:maven-archetype-plugin:2.4:create for parameter #: Cannot create instance of interface org.apache.maven.artifact.repository.ArtifactRepository -> [Help 1]

[ERROR]

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR]

第一步:建立web項目:

cd到希望項目存儲的檔案夾下,執行以下指令

mvn archetype:generate  -DgroupId=包名 -DartifactId=項目名稱 -DarchetypeArtifactId=maven-archetype-webapp

(如果是建立javaProject則是:mvn archetype:generate -DgroupId=包名 -DartifactId=項目名稱 )

例如:

mvn archetype:generate  -DgroupId=com.lyx -DartifactId=snatchWeb -DarchetypeArtifactId=maven-archetype-webapp

過程中可能會讓你選擇你直接回車選擇預設的選項就可以

當出現 BUILD SUCESS 表示maven項目建立成功了,你可以去項目所在的檔案下在看是否存在。

第二步:生成eclipse項目檔案

如果需要導入到Eclispe編譯器中還需要生成所需的.classpath和project檔案

這時 cd到該項目的項目名稱下執行 mvn eclipse:eclipse 指令

這樣就可以建立完成了。