pom檔案以及maven命令
阿新 • • 發佈:2018-12-12
一、pom檔案
1.依賴
<dependency> <groupId>com.google.guava</groupId> //組織名,一般為包名 <artifactId>guava</artifactId> //專案名 <version>19.0</version> //版本號 <scope>compile</scope> //範圍,有test,compile(編譯),runtime(執行,例如jdbc驅動等) <exclusions> //排除依賴中的某個依賴,常用於解決依賴衝突 <exclusion> //依賴 </exclusion> </exclusions> </dependency>
2.打包方式,多模組
<packaging>pom</packaging> //如果當前專案是獨立的專案,則用jar,如果當前專案是其他專案的父專案,則用pom打包方式
<modules> //子模組
<module>service</module> //在子模組中需要使用<parent>標籤進行父專案的設定
<module>dao</module>
</modules>
3.父專案
<parent> //當前專案的父專案 <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> </parent>
4.定義變數
<properties>
<java-version>1.8</java-version> //標籤名就是變數的名字
</properties>
使用: <version>${java-version}</version> 使用${}既可以讀取pom檔案中的變數,也可以讀取配置檔案中的變數
4.編譯
<build> <finalName>file</finalName> //最終打包的檔名 <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> //jdk版本 <target>1.8</target> <compilerArgument>-Xlint:all</compilerArgument> //編譯引數 <showWarnings>true</showWarnings> <showDeprecation>true</showDeprecation> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
二、maven命令
1. mvn clean 清理專案生產的臨時檔案,一般為target目錄
2.mvn package 打包,會在target下生成jar檔案或war
3.mvn test : 執行 src/test/java下的測試用例
4.mvn install 模組安裝命令 將打包的的jar/war檔案複製到你的本地倉庫中,供其他模組使用
5.mvn dependency:tree 檢視依賴情況,
6.mvn dependency:analyze 幫助你分析依賴關係, 用來取出無用, 重複依賴的好幫手