文章目录
- 前言
- 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>