惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Vercel News
Vercel News
F
Fortinet All Blogs
月光博客
月光博客
G
Google Developers Blog
博客园 - Franky
GbyAI
GbyAI
The Cloudflare Blog
I
InfoQ
雷峰网
雷峰网
WordPress大学
WordPress大学
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 聂微东
小众软件
小众软件
腾讯CDC
B
Blog
量子位
V
V2EX
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News

jobcher on 打工人日志

2023-12-21 打工人日报 2023-12-20 打工人日报 2023-12-19 打工人日报 2023-12-18 打工人日报 2023-12-17 打工人日报 2023-12-16 打工人日报 2023-12-15 打工人日报 2023-12-14 打工人日报 2023-12-13 打工人日报 2023-12-12 打工人日报 2023-12-11 打工人日报 2023-12-10 打工人日报 2023-12-09 打工人日报 2023-12-08 打工人日报 2023-12-07 打工人日报 2023-12-06 打工人日报 2023-12-05 打工人日报 2023-12-04 打工人日报 2023-12-03 打工人日报 2023-12-02 打工人日报 2023-12-01 打工人日报 2023-11-30 打工人日报 2023-11-29 打工人日报 2023-11-28 打工人日报 2023-11-27 打工人日报 2023-11-26 打工人日报 2023-11-25 打工人日报 2023-11-24 打工人日报 2023-11-23 打工人日报 2023-11-22 打工人日报
Maven 安装编译
2022-03-03 · via jobcher on 打工人日志

Maven 安装编译

Maven 就是专门为 Java 项目打造的管理和构建工具,它的主要功能有:

  • 提供了一套标准化的项目结构;
  • 提供了一套标准化的构建流程(编译,测试,打包,发布……);
  • 提供了一套依赖管理机制。

默认结构:

 1a-maven-project
 2├── pom.xml
 3├── src
 4│   ├── main
 5│   │   ├── java
 6│   │   └── resources
 7│   └── test
 8│       ├── java
 9│       └── resources
10└── target

项目的根目录a-maven-project是项目名,
它有一个项目描述文件pom.xml
存放Java源码的目录是src/main/java
存放资源文件的目录是src/main/resources
存放测试源码的目录是src/test/java
存放测试资源的目录是src/test/resources
最后,所有编译、打包生成的文件都放在target目录里。
这些就是一个 Maven 项目的标准目录结构。

pom.xml 文件:

 1<project ...>
 2	<modelVersion>4.0.0</modelVersion>
 3	<groupId>com.itranswarp.learnjava</groupId>
 4	<artifactId>hello</artifactId>
 5	<version>1.0</version>
 6	<packaging>jar</packaging>
 7	<properties>
 8        ...
 9	</properties>
10	<dependencies>
11        <dependency>
12            <groupId>commons-logging</groupId>
13            <artifactId>commons-logging</artifactId>
14            <version>1.2</version>
15        </dependency>
16	</dependencies>
17</project>

groupId类似于 Java 的包名,通常是公司或组织名称,
artifactId类似于 Java 的类名,通常是项目名称,
version,一个 Maven 工程就是由groupId,artifactId和version作为唯一标识。
我们在引用其他第三方库的时候,也是通过这 3 个变量确定。

依赖commons-logging

1<dependency>
2    <groupId>commons-logging</groupId>
3    <artifactId>commons-logging</artifactId>
4    <version>1.2</version>
5</dependency>

使用<dependency>声明一个依赖后,Maven 就会自动下载这个依赖包并把它放到classpath中。

安装 Maven