- 编写源代码
- 安装Maven约定,源代码要存放在src/java/main,所以依次创建三个目录
- 按照POM中的<groupId>com.wys.myapp</groupId>和<artifactId>HelloWord</artifactId>创建目录:com\wys\myapp\helloWorld,这个目录是约定存在本项目的Java源代码的,所以最后的目录是:
- 创建HelloWorld.java源代码文件:
- 切换到项目的根目录,也就是POM.xml文件所在目录
[c:\~]$ cd D:\MavenTest\HelloWord
- 执行情况和编译目录
[D:\MavenTest\HelloWord]$ mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building My first Maven project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloWord ---
[INFO] Deleting D:\MavenTest\HelloWord\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWord ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\MavenTest\HelloWord\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ HelloWord ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\MavenTest\HelloWord\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.277 s
[INFO] Finished at: 2018-08-02T13:35:47+08:00
[INFO] Final Memory: 13M/108M
[INFO] ------------------------------------------------------------------------
- 完成后Maven自动新建target目录存在class文件
- 在POM.xml下新增加依赖:junit(单元测试jar包)和新的控件
- 新的依赖
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies>
- 新的插件
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <targer>1.5</targer> </configuration> </plugin> </plugins> </build>
》》》》》未完:易学笔记-Maven教程--入门就看这一篇就够了》》》》》
- 新的依赖