这里默认已经安装好了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命令
这样就可以创建完成了。