文章目錄
- 前言
- Maven常用命令
- 1.clean
- 2.vaildate
- 3.compile
- 4.test
- 5.package
- 6.verify
- 7.install
- 8.site
- 9.deploy
- pom.xml標簽詳解
- 格式
- <?xml version="1.0" encoding="UTF-8"?>(xml版本和編碼)
- modelVersion(xml版本)
- groupId(項目的組名,通常是反轉的域名,比如com.example)
- artifactId(項目唯一標識符,通常是項目的名稱)
- version(項目的版本好)
- packaging(項目打包方式,通常是jar、war、pom。默認是jar)
- name(項目名)
- description(項目描述)
- licenses(許可證聲明)
- developers(開發者信息)
- url(項目主頁,提供項目網址)
- modules(子模塊信息)
- parent(父模塊信息)
- properties(統一管理項目中常用的屬性,比如版本號,路徑等信息)
- dependencies(項目依賴信息)
- repository(指定倉庫)
- build(定義項目的構建配置,包括源代碼目錄、資源目錄、插件等)
- plugins(定義 Maven 插件, plugins 主要用于擴展 Maven 的功能)
前言
現在java開發使用最多的就是springboot項目,使用springboot項目最多的就是maven工具,記錄一下常用的命令,以免忘記
Maven常用命令
1.clean
刪除由以前的生成的所有文件。
2.vaildate
驗證項目是否正確,以及所有必要的信息是否可用。
3.compile
編譯 Java 源代碼。
4.test
使用合適的單元測試框架測試編譯的源代碼,這些測試不應該要求打包或部署代碼。
5.package
將編譯后的代碼打包為可分發的格式,例如JAR。
6.verify
驗證-對集成測試的結果進行任何檢查,以確保符合質量標準
7.install
將包安裝到本地存儲庫中,用作本地其他項目的依賴項。
8.site
生成項目的現場文檔 。
9.deploy
在構建環境中完成,將最終包復制到遠程存儲庫,以便與其他開發人員和項目共享。
pom.xml標簽詳解
格式
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>example-proj</artifactId><version>1.0.0</version><name>Example Project</name><description>This is an example Maven project.</description><url>http://www.example.com/</url><licenses> <!-- 許可證 --><license><name>The Apache Software License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url><distribution>repo</distribution></license></licenses><developers> <!-- 開發者信息 --><developer><id>developer1</id><name>Developer One</name><email>developer1@example.com</email><organization>Example Organizations Inc.</organization><organizationUrl>http://www.example-organizations.com/</organizationUrl><roles><role>developer</role></roles><timezone>-5</timezone></developer></developers><dependencies> <!-- 依賴項 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>5.2.1.RELEASE</version></dependency></dependencies><build> <!-- 項目構建 --><plugins> <!-- 插件配置 --><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.2.0</version><configuration><archive><manifest><addClasspath>true</addClasspath><mainClass>com.example.App</mainClass></manifest></archive></configuration></plugin></plugins></build>
</project>
<?xml version="1.0" encoding="UTF-8"?>(xml版本和編碼)
modelVersion(xml版本)
groupId(項目的組名,通常是反轉的域名,比如com.example)
artifactId(項目唯一標識符,通常是項目的名稱)
version(項目的版本好)
packaging(項目打包方式,通常是jar、war、pom。默認是jar)
name(項目名)
description(項目描述)
licenses(許可證聲明)
developers(開發者信息)
url(項目主頁,提供項目網址)
modules(子模塊信息)
parent(父模塊信息)
properties(統一管理項目中常用的屬性,比如版本號,路徑等信息)
<properties><project.name>demo-project</project.name><project.version>1.0.0</project.version><jdk.version>1.8</jdk.version>
</properties>
dependencies(項目依賴信息)
<dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>5.2.1.RELEASE</version></dependency>
<groupId>:指定依賴項的groupId,項目的組名
<artifactId>:指定依賴項的artifactId,項目的唯一標識符
<version>:指定依賴項的版本號。
<scope>:指定依賴項在項目中的使用范圍。常用的有compile、test、provided 和 runtimecompile: 依賴庫默認的 scope,表示該依賴庫在編譯、測試、運行時均需要使用。provided: 表示該依賴庫只在編譯和測試時需要使用,而在運行時已經被系統或者容器提供,所以不需要打包到最終的應用程序中。runtime: 表示該依賴庫只在運行時需要使用,而在編譯和測試時則不需要。test: 表示該依賴庫只在測試時需要使用,而在編譯和運行時則不需要。 比如說我們引入了 junit 包,但顯然這個包我們不需要在打包時包含,只是用于測試,那么我們就可以將 junit 的 scope 設置為 test。
repository(指定倉庫)
<repositories><repository><id>aliyun-maven</id><name>aliyun-maven</name><url>https://</url></repository>
</repositories>
<id>:指定Maven倉庫的ID。
<name>:指定Maven倉庫的名稱。
<url>:指定Maven倉庫的URL
build(定義項目的構建配置,包括源代碼目錄、資源目錄、插件等)
<project>.... 省略其他部分<build><sourceDirectory>src/main/java</sourceDirectory><!--代碼路徑--><resources><resource><directory>src/main/resources</directory><!--資源文件路徑--></resource></resources><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>
</project>