第3章:Maven使用入門/3.2 編寫原始碼
- 編寫原始碼
- 安裝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教程--入門就看這一篇就夠了》》》》》
- 新的依賴