Hello, today’s Maven for you kids, take out your little notebook and write it down

Chapter 1 Introduction to Maven

1.1 Stages in software development

Need analysis: analyze the specific functions completed by the project, what requirements are there, and how to achieve them.

Design stage: according to the results of analysis, design what technology to use in the project and solve the difficulties.

Development stage: coding to realize functions. Compile the code. Self test

Testing stage: professional testers test the function of the whole project to meet the design requirements. Produce a test report.

Package the project, release phase: Install the project to the user

1.2 What does Maven do

1) Automatic construction of projects, helping developers to compile, test, package, install and deploy project codes.

2) Manage dependencies (manage the various JAR packages used in the project).

Dependencies: Other resources that need to be used in a project, most commonly jars. For example, the project will use the mysql driver. Let’s say the project relies on the mysql driver.

1.3 How to manage dependencies without Using Maven

To manage jars, you need to download a separate JAR from the network

Select the correct version

Manually handle dependencies between JAR files. A. jar inside to use b.jar class.

1.4 What is Maven

Maven is an open source project of the Apache Foundation, developed using Java syntax. Maven: Expert, expert. It is pronounced [‘meɪv(ə)n] or [‘mevn].

Maven is an automated build tool for projects. Manage project dependencies.

1.5 Concepts in Maven

① Project Object Model (POM)

② The agreed directory structure

(3) coordinates

④ Dependency management

⑤ Warehouse management

⑥ Life cycle

⑦ Plugins and goals

Today inheritance

Pet-name ruby polymerization

1.6 Obtaining and Installing Maven Tools

Installation:

JAVA_HOME specifies the JDK installation directory. If JAVA_HOME is not available, create JAVA_HOME in the Windows environment variable. Its value is the JDK installation directory (create JAVA_HOME first, then add % XXX %\bin to path).

Unzip apache-maven-3.3.9-bin.zip and put the decompressed file in a directory. The directory path should not have Chinese characters or Spaces.

Add the bin path in the Maven installation directory to path

Test your Maven installation. Run MVN -v on the command line

Maven decompressed directory structure

Other ways to install Maven:

Determine whether JAVA_HOME is valid

In the environment variable, create one called M2_HOME (or MAVEN_HOME), whose value is the maven installation directory M2_HOME=D:\tools\apache-maven-3.3.9

In the path environment variable, add %M2_HOME%\bin

To test maven’s installation, run MVN -v from the command line

The second chapter is the core concept of Maven

2.1 Common directory structure

The directory structure used by the Maven project is the one most people follow. It’s called the convention directory structure.

A Maven project is a folder. For example, the project is called Hello

How to use Maven:

1) Maven can be used independently: create projects, compile code, test programs, package, deploy, etc

2) Use Maven with IDEA: Implement coding, testing, packaging and so on with Maven via IDEA

2.2 the POM

Maven treats the Project as a Model. Manipulating the model is manipulating the project.

Maven implements project build and dependency management through the POM.xml file.

2.3 coordinates

The coordinate composition is Groupid, artifiactId, Version. The concept of coordinates comes from mathematics. ,

Coordinate function: Identifies the unique identifier of a resource. In Maven, every resource is a coordinate. Coordinate values are unique. Referred to as “called gav

The project uses GAV:

Each Maven project needs to have its own GAV

To manage dependencies, you need to use additional JARS (also identified by GAV).

Address of the search coordinates: mvnrepository.com/

2.4 relies on the dependency

Dependencies: Other resources (jars) to be used in the project.

You need to use Maven to represent dependencies and manage dependencies. Dependencies are used together with dependency and GAv

You need to use dependencies and dependency in the POM.xml file, along with instructions for completing dependencies in GAv.

Format:

2.5 warehouse

Maven’s repository is for storing things. Maven’s repository is for storing:

Maven tool’s own JAR package.

Other third-party jars, such as mysql drivers, are used in projects.

Write their own procedures, can be packaged as jar, stored in the warehouse.

Classification of warehouse:

Local repository (native repository) : located on your own computer, it is a directory on disk.

Local repository: The default path is /.m2/repository in the directory where you log in to the operating system

C:\Users\NING MEI.m2\repository

Change the location of the local repository: Change the configuration file of the Maven tool (maven installation path \conf\setting.xml)

Steps:

1) Create a directory for use as a repository. Do not have Chinese and Spaces in the directory. Don’t be too deep.

For example: D: \ openrepository

2) Modify setting. XML file to specify D:\ openRepository directory

D:/openrepository

Remote warehouse: needs to be accessed through the network

1) Central repository: an FTP server where all resources are stored.

2) Central warehouse mirror: is a copy of the central warehouse. It is mirrored in every major city.

3) Private server: used in the LAN. Private servers are their own warehouse servers. For use within the company.

Maven uses the repository: Maven automatically uses the repository. When a project is started and maven commands are executed, Maven first accesses the local repository to obtain the required JARS from the repository. If the local repository does not exist, Maven needs to access the private server or central repository or image.

2.6 Maven’s life cycle, plug-ins and commands

Maven’s life cycle: The phases of project construction. This includes cleaning, compiling, testing, reporting, packaging, installing, and deploying.

Plugins: To complete the various stages of a build project, maven commands are used. The execution of commands is done through plugins. Plug-ins are Jars, classes.

Command: Executing maven functions is issued by command. Such as MVN compile

Unit Tests (junit) :

Junit is a unit testing tool that is often used in Java.

Unit: In Java, methods. A method is a unit, and a method is the smallest unit of testing.

Purpose: Use junit to test whether a method fulfils its requirements. Developers test themselves.

Using unit tests:

1) Add junit’s dependencies (some classes and methods)

2) Create the test class file in the SRC /test/ Java directory. Write test code

Tips for using unit tests:

1. The definition of the Test class, usually named Test+ the name of the class to be tested

The package name is the same as the package name of the class to be tested.

3. Define methods in a class and test your code.

Method definition: public method,

No return value

Custom method name (Test+ Test method name is recommended)

Method has no parameters

4. Methods in the test class can be executed separately. The test class can also be executed separately

5. Add @test above the method

Command:

1) MVN clean: deletes previously generated data and deletes the target directory.

Plugin: Maven-clean-plugin, version 2.5

SRC /main/ Java directory to compile Java code into class files.

Copy the class file to the target/classes directory as well. Classes is the root directory where class files are stored (also called classpath, classpath).

Maven-compiler-plugin version 3.1. A plug-in that compiles code

Maven-resources-plugin version 2.6. Resource plug-in, processing files. SRC /main/resources directory

Copy files to target/classes directory.

3) MVN test-compile: compile the source files in SRC /test/ Java and copy the generated classes to target/test-classes. Copy the files from SRC /test/resources to the test-clasess directory

Maven-compiler-plugin version 3.1. A plug-in that compiles code

Maven-resources-plugin version 2.6. Resource plug-in, processing files

SRC /main/ Java/MVN/MVN/MVN/MVN/MVN/MVN/MVN/MVN/MVN/MVN

Maven-surefire-plugin version 2.12.4

5) MVN package: package the resource class file and configuration file in the project into a compressed file, the default compressed file is jar type. The Web application is war, and the extension is JAR, WAR.

Plugin: Maven-jar-plugin version 2.4 Perform packaging. Generate a jar extension file and place it in the target directory.

The package contains all generated classes and configuration files in the SRC /main directory, independent of test.

Jar ch01-Maven-1.0-snapshot.jar

6) MVN install: Install the generated package into maven repository.

Maven-install-plugin version 2.4. Install the generated JAR files into the local repository.

View the JAR files in view:

7) MVN deploy the main program (will package the project, according to the coordinates of the project saved to the local library, and will also save to the private server repository. The project is also automatically deployed into the Web container).

2.7 Custom Configuration Plug-ins

In the pom.xml file, in the build tag. Set up the plugin

Chapter 3 Integration of Maven and IDEA

3.1 Idea Integrated with Maven

Idea has a built-in Maven. We want IDEA to use our own maven installation.

Choose File – Settings

Setting: -DarcheTypecatalog =internal

2) File-other Settings

Same Settings as above

3.2 Creating a regular Java project based on Maven

3.3 Creating a Web Project

3.4 Importing Module to IDEA

Chapter 4 Dependency management

Dependency scope: Use scope to indicate the scope of a dependency.

Dependency scope indicates that the dependency (jar and its classes) is in effect at that stage of project construction.

Scope:

Compile: Default and participate in all stages of building the project

Test: tests, used in the test phase, such as junit used to execute MVN test.

Provided: the provider. When a project is deployed to a server, it does not need to provide the dependent JAR, but rather the dependent JAR package of the server

The obvious ones are servlet and JSP dependencies

Chapter 5 Common Settings

1) Properties

The global variable

In properties, you define the tag, which is a variable, and the text of the tag is the value of the variable.

Use global variables to represent the version numbers used by multiple dependencies.

Use steps:

1. In the Properties TAB, define a tag that specifies the value of the version

${var name} ${var name}

3) Use resource plug-ins

Maven handles configuration files by default

Maven will copy files from SRC /main/resources to target/classes

Maven only processes.java files in SRC /main/ Java. Compile these Java files into classes and copy them to target/classes. Do not process other files.

Well, this is the end of today’s article, I hope to help you confused in front of the screen