maven创建helloword项目

[root@666 maven_work]# mvn archetype:create -DgroupId=helloword -DartifactId=helloworld
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.493 s
[INFO] Finished at: 2017-11-27T14:46:23+08:00
[INFO] Final Memory: 7M/145M
[INFO] ------------------------------------------------------------------------
[ERROR] Could not find goal 'create' in plugin org.apache.maven.plugins:maven-archetype-plugin:3.0.1 among available goals crawl, create-from-project, generate, help, integration-test, jar, update-local-catalog -> [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] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoNotFoundException
以create报错
[root@666 maven_work]# mvn archetype:create -DgroupId=helloword -DartifactId[root@666 maven_work]# mvn archetype:generate -DgroupId=helloword -DartifactId=helloworld
成功!!
生成以下文件:
# tree helloworld/
helloworld/
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- helloword
    |           `-- App.java
    `-- test
        `-- java
            `-- helloword
                `-- AppTest.java

7 directories, 3 files

 进到项目中,然后进行:

# cd helloworld/
[root@666 helloworld]# ls
pom.xml  src
[root@666 helloworld]# mvn package 
第一次编译的话,需要联网,因为Maven会自动下载依赖包.成功后会生成:target文件夹
[root@666 helloworld]# ls
pom.xml  src  target

[root@666 helloworld]# tree target/
target/
|-- classes
|   `-- helloword
|       `-- App.class
|-- helloworld-1.0v.jar
|-- maven-archiver
|   `-- pom.properties
|-- maven-status
|   `-- maven-compiler-plugin
|       |-- compile
|       |   `-- default-compile
|       |       |-- createdFiles.lst
|       |       `-- inputFiles.lst
|       `-- testCompile
|           `-- default-testCompile
|               |-- createdFiles.lst
|               `-- inputFiles.lst
|-- surefire-reports
|   |-- helloword.AppTest.txt
|   `-- TEST-helloword.AppTest.xml
`-- test-classes
    `-- helloword
        `-- AppTest.class

12 directories, 10 files

 手动运行jar包查看结果

# java -cp target/helloworld-1.0v.jar helloword.App
Hello World!

 

这里列举几个常用的命令

mvn compile 编译项目
mvn test 编译运行单元测试
mvn package 打包(jar or war)
mvn install 将项目安装到本地仓库
mvn clean 清空项目
mvn eclipse:eclipse 生成eclipse工程
posted @ 2017-11-27 15:20  bass  阅读(951)  评论(0编辑  收藏  举报