Maven-Basic
Maven is a project build tool. Used for dependency management.
- Benefits of Maven
Use traditional project development, project size:
use Maven to develop:
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.
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 :
- 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
2. Unzip it to the local disk, pay attention to the decompression directory without Chinese characters and spaces
3. Configure the environment variable
"Computer", right-click "Properties", find "Advanced System Configuration", click "Environment Variables"
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".
Configure the maven_home environment variable into the path environment variable
Precondition: There is a jdk environment variable: JAVA_HOME
Query the maven version information to test whether the installation is successful:
4. Configure the local warehouse:
Repository type: local warehouse, private server, central warehouse
Download bos.repository.zip address, see http://t.csdn.cn/LwXU2 for details
and decompress to local disk
Next, configure the local warehouse and let the maven program know where the warehouse is
. Open the maven configuration file settings.xml
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
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:
src source file:
Import the directory structure of the maven project in eclipse:
Maven's common commands (application)
- clean: clean up
Clean up the target directory (that is, the .class file) under the project root directory.
- compile: compile
compiles the .java file in the project into a .class file
- 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
- 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 project - install: Install
to solve the problem of multiple local projects sharing a jar package
and package it into the local warehouse.
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