catalogue
II Maven's configuration file - POM xml
2. In POM Configure dependency in XML file
IV Lifecycle and its related commands
V Order in which Maven loads dependent packages
I What is Maven
Maven: project construction tool, packaging tool
Maven project file structure:
src\
main\
Java \ --- java code for project development
resources \ -- resource folder for project development
test\
java \ --- unit test code (self-test by developers)
pom.xml -- configuration file of the current project
Based on POM XML configuration, use maven command to complete the project construction
Maven common configuration
(1). Dependency configuration: specifies which dependency package to use
(2). Specify some common configurations: jdk version, encoding, etc
Maven's role
Project construction: Project dependency, project packaging
II Maven's configuration file - POM xml
Note: after changing the xml file, be sure to refresh it
Xml simple content: tag, tag attribute
There are two ways to define labels:
There is no change before modelversion (pom version)
<?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/xsd/maven-4.0.0.xsd"> <!-- Don't worry about the above content at all. Just use the automatic generation, which is specified by some verification rules --> <!-- What is specified here is POM The version of does not need to be moved --> <modelVersion>4.0.0</modelVersion>
Then, the following groupid, artifactid and version correspond to the organization number, product number and version number of the current project, which we can modify ourselves
<!-- Organization name, product name and version number form a unique product identification --> <!-- organization id: Usually the company name --> <groupId>Zebra</groupId> <!-- Product Name: the current project is a product, which is provided to others. What is the product name --> <artifactId>servlet_study</artifactId> <!-- Version number: --> <version>1.0</version>
Next, you can configure some other things, such as jdk version, dependency package, etc
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>
III Dependency management
1.maven warehouse
maven warehouse is similar to the App Store on mobile phones. There will be various third-party jar packages uploaded by people all over the world for us to use. When our projects need to use the contents, it can be found and installed as easily as installing app on mobile phones.
Our project uses another project called dependency.
A project often needs a lot of dependencies, so the concept of dependency management was born.
2. In POM Configure dependency in XML file
<!-- Configure dependent packages --> <dependencies> <!-- The dependent package also needs to specify the unique identification of the product (three) --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.49</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> </dependencies>
When adding dependencies, you should also specify groupId,artifactId,version and idea. The idea will find it locally first. If it cannot be found locally, the idea will automatically start downloading
IV Lifecycle and its related commands
- clean: clear target directory
- Compile: compile the current file and generate relevant compiled files in the target directory
- package: type the classes in the current project into jar packages for others to use
- Install: install the jar package in target to the local warehouse
- deploy: submit the jar package in the target to the company's remote warehouse for use by other team members
V Order in which Maven loads dependent packages
Maven loads dependent packages in the following order:
Local warehouse - configured remote warehouse (Alibaba cloud) - Official remote warehouse