Maven常用命令-创建Java项目

最后更新于:2022-04-01 20:45:22

我们之前使用Maven都是直接在Eclipse中创建的,有的时候步骤稍微冒犯些 这里我们学习下怎样用命令创建项目 参考网址: [http://www.cnblogs.com/PatrickLee/archive/2012/10/31/2747398.html](http://www.cnblogs.com/PatrickLee/archive/2012/10/31/2747398.html) 感谢分享。 1. 创建Java项目 ~~~ yuguiyang@onepiece:~/Documents/maven_demo$ mvn archetype:create \ > -DgroupId=org.ygy \ > -DartifactId=hello_maven ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-09-06_57ce64ffee92e.jpg) 首次运行命令时,maven会下载一些依赖的jar包 我们等待她运行完就可以了 ~~~ yuguiyang@onepiece:~/Documents/maven_demo$ mvn archetype:create \ > -DgroupId=org.ygy \ > -DartifactId=hello_maven [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-archetype-plugin:2.2:create (default-cli) @ standalone-pom --- [WARNING] This goal is deprecated. Please use mvn archetype:generate instead [INFO] Defaulting package to group ID: org.ygy [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:RELEASE [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: org.ygy [INFO] Parameter: packageName, Value: org.ygy [INFO] Parameter: package, Value: org.ygy [INFO] Parameter: artifactId, Value: hello_maven [INFO] Parameter: basedir, Value: /home/yuguiyang/Documents/maven_demo [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] project created from Old (1.x) Archetype in dir: /home/yuguiyang/Documents/maven_demo/hello_maven [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.439 s [INFO] Finished at: 2014-10-13T10:01:41+08:00 [INFO] Final Memory: 13M/310M [INFO] ------------------------------------------------------------------------ yuguiyang@onepiece:~/Documents/maven_demo$ ~~~ 等看到BUILD SUCCESS就可以了 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-09-06_57ce65000ea2c.jpg) (PS 在上面的日志中,我们看到一条警告 [WARNING] This goal is deprecated. Please use mvn archetype:generate instead 目测是说我们的命令中 mvn archetype:create \ 已经不推荐使用了,废弃掉了,使用 mvn archetype:generate 代替 我们试下 ~~~ yuguiyang@onepiece:~/Documents/maven_demo$ mvn archetype:generate \ > -DgroupId=org.ygy \ > -DartifactId=new_code ~~~ 这次执行时,又下载了一大堆jar包,中间还提示说要选择版本,直接Enter选择默认了 最后也是执行成功了的 以后我们还是使用官方推荐的命令吧 )
';