Maven core features

1. Common commands of Maven

1. comopile
compile is the compilation command of the maven project. Its function is to compile the files under src / main / java into class files and output them to the target directory.

The cmd enters the command state and executes mvn compile. The following figure prompts success:

 

 Check the target directory, the class file has been generated, and the compilation is complete.

 

 

2. test
test is the test command mvn test of the maven project, which will execute the unit test class under src / test / java.
cmd executes mvn test to execute the unit test class under src / test / java. The following figure shows the test results. One test case was run and all succeeded.
3. Clean
clean is the clean command of the maven project. Executing clean will delete the target directory and contents. After you enter the company, you generally need to clean other people ’s code.
4. The package
package is the packaging command of the maven project. For the java project , the package is converted into a jar package, and for the web project, it is called a war package.
5. Install
install is the installation command of maven project, execute install to publish maven into jar package or war package and publish it to local warehouse.
From the operation results, it can be seen that
when the following commands are executed, the previous operation process will also be automatically executed,

Second, Maven's life cycle

 

 

When the following commands are executed, the previous commands are automatically executed.
Maven divides the project construction process into three sets of independent life cycles. Please note that here are "three sets" and "independent". These three sets of life cycles They are:

Clean Lifecycle performs some cleanup work before the actual build.
The core part of the Default Lifecycle build, compile, test, package, deploy, etc.
Site Lifecycle generates project reports, sites, and publishing sites.

Three, Maven conceptual model diagram

Project object model (Project Object Model)
A maven project has a pom.xml file, through which the coordinates, project dependencies, project information, plug-in targets, etc. of the project are defined.

Dependency Management System (Dependency Management System)
through maven dependency management for the unified management of jar packages that the project depends on.
For example: The project depends on junit4.9, and junit4.9 is used by defining the dependency of junit4.9 in pom.xml, as shown below is the dependency definition of junit4.9:

<!-Dependency->
    <dependencies>
        <!-This project runs using junit, so this project depends on junit->
        <dependency>
            <!-junit's project name->
            <groupId>junit</groupId>
            <!-junit module name->
            <artifactId>junit</artifactId>
            <!-junit version->
            <version>4.9</version>
            <!-Dependency range: use junit for unit testing->
            <scope>test</scope>
        </dependency>

  A Project Lifecycle
uses maven to complete the project construction. Project construction includes: cleaning, compiling, testing, deploying and other processes. Maven standardizes these processes as a life cycle. The following are the stages of the life cycle:

 

 

Maven can implement various processes of the above life cycle by executing some simple commands, such as executing mvn compile to perform compilation, and mvn clean to perform cleaning.

A set of standard collections
maven defines a set of standards for the entire project management process, for example: a standard directory structure for a project built through maven, a standard life cycle stage, and standard coordinate definitions for dependency management.

Plugin (goal) goal
Maven management project life cycle process is based on plugins.

Four, dependent scope

A depends on B. The coordinates of B need to be added in the pom.xml file of A. When adding coordinates, you need to specify the dependent range.

compile: Compile scope, which means that A depends on B during compilation. This scope is the default dependent scope. Compile-range dependencies will be used for compilation, testing, and running. Compile-range dependencies will be packaged due to runtime requirements.

provided: The provided dependency is only used after the JDK or a container has provided the dependency. The provided dependency is required during compilation and testing, but not at runtime. For example, the servlet api is provided by the tomcat container.

runtime: The runtime dependency is needed when running and testing the system, but not when compiling. For example: jdbc driver package. Due to runtime requirements, runtime-wide dependencies will be packaged.

test: Test range dependencies are not required during compilation and operation, they are only available during test compilation and test operation, such as junit. Since it is not needed at runtime, the test scope dependency will not be packaged.

system: The system range dependency is similar to provided, but you must explicitly provide a path to the JAR file in the local system. You need to specify the systemPath disk path. System dependency is not recommended.

 

 

Test each scop in the maven-web project.

Test summary:

The jar package introduced by default ------- compile [the default range can not be written] (compile, test, and run are valid)
servlet-api, jsp-api ------- provided (compile and test are valid, Invalid at runtime to prevent conflict with jar under tomcat)
jdbc driver jar package ---- runtime (testing, running effective)
junit ----- test (testing effective)

The order of dependency range from strong to weak is: compile> provided> runtime> test

5. Engineering unpacking and polymerization

 

 From: https://www.jianshu.com/p/0f83680bb0eb



Guess you like

Origin www.cnblogs.com/hnusthuyanhua/p/12703038.html