Maven project management tool foundation and download and installation

Maven-Basic

Maven is a project build tool. Used for dependency management.

  • Benefits of Maven

Use traditional project development, project size:
insert image description here
use Maven to develop:
insert image description here
there is no jar package in the Maven project, but you need to use the jar package:
there is a jar package warehouse, and maven uses the coordinates to find the jar package

As a jar package, how to give the coordinates?
For example: struts2-core-2.3.24.jar
Apache (company name) + struts2 (project name) + 2.3.24 (version information)

The maven project requires a certain jar package, and there is no need to import the jar package. You only need to configure the coordinate information of the required jar package in the maven project.
The maven program searches the jar package in the jar package warehouse according to the coordinate information of the jar package.
jar package warehouse, also known as maven warehouse.

insert image description here
Dependency management (the first core of maven): it is the unified management
of jar packages

  • How the benefits of Maven are realized

The two cores of maven:
Dependency management : The process of jar package management
Project construction : After the project is coded, a series of operations such as compiling, testing, packaging, and deploying the project are realized through commands .

Publish the web project to tomcat through the maven command :insert image description here

  • Maven installs and configures local warehouse

Maven program installation premise: maven program java development, its operation depends on jdk.

Download and install maven, refer to http://t.csdn.cn/W8Drh

1. Download the compressed package
insert image description here
2. Unzip it to the local disk, pay attention to the decompression directory without Chinese characters and spaces
insert image description here
3. Configure the environment variable
"Computer", right-click "Properties", find "Advanced System Configuration", click "Environment Variables"
insert image description here
insert image description here
insert image description here
in "System Variables" "Create a new variable in ", the variable name is "MAVEN_HOME", the variable value is the path of the installed maven file, click "OK".
insert image description here

Configure the maven_home environment variable into the path environment variable
insert image description here
insert image description here
Precondition: There is a jdk environment variable: JAVA_HOME

Query the maven version information to test whether the installation is successful:
insert image description here
4. Configure the local warehouse:

Repository type: local warehouse, private server, central warehouse
insert image description here
Download bos.repository.zip address, see http://t.csdn.cn/LwXU2 for details
insert image description here
and decompress to local disk
insert image description here

Next, configure the local warehouse and let the maven program know where the warehouse is
. Open the maven configuration file settings.xml
insert image description here

Find a comment section of the "localRepository" label, add a sentence under the comment, and <localRepository>D:\Maven\bos_repository</localRepository>
change the path between the label pairs to the path after decompressing the bos_repository file
insert image description here

Remark:

	 <!--  配置阿里云  -->
<mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>*</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

//配置jdk
<profile>
    <id>jdk-1.8</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
    </activation>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
</profile>

Maven project standard directory structure
Maven project root directory:
insert image description here
src source file:
insert image description here

Import the directory structure of the maven project in eclipse:
insert image description here

Maven's common commands (application)

  • clean: clean up

Clean up the target directory (that is, the .class file) under the project root directory.
insert image description here
insert image description here
insert image description here
insert image description here

  • compile: compile
    compiles the .java file in the project into a .class file
    insert image description here
    insert image description here
    insert image description here
    insert image description here
  • test: unit test
    will execute the unit test classes in the src/test/java directory under the project root directory.
    The unit test class name is required: XxxTest.java
    insert image description here
    insert image description here
  • package: package
    web project --> war package
    java project --> jar package
    to package the project, and package the target directory under the root directory of the projectinsert image description here insert image description here
  • install: Install
    to solve the problem of multiple local projects sharing a jar package
    and package it into the local warehouse.
    insert image description here
    insert image description here
    insert image description here
    It is found that among these commands, every time a command is executed, the previous command will be executed again. This is called: life cycle

Life cycle of maven project (*):
There are three sets of life cycles in maven, and each set of life cycles is independent of each other and does not affect each other.
In a set of life cycles, execute the following commands, and the previous operations will be executed automatically.

CleanLifeCycle: clean life cycle

clean

defaultLifeCycle: default life cycle

compile,test,package,install,deploy

siteLifeCycle: site life cycle

site

Guess you like

Origin blog.csdn.net/weixin_47678894/article/details/126060981