table of Contents
1.2 What problems can Maven solve
1.3 Two core functions of Maven [Key]
Two Maven installation and use
2.1 Maven download and installation
2.2 Maven Warehouse [Key Points]
2.2.1 Classification of Maven Warehouse
2.2.2 Maven local warehouse configuration
2.2.3 Maven warehouse domestic mirror configuration
2.3 Maven coordinates and dependencies
2.4 Structure of Maven Project [Key Points]
Three Maven life cycle and plugins
3.1 Maven commonly used commands and plugins
1)clean 2)compile 3)test 4)package 5)install 6)deploy
Four IDEA to create a Maven project [key]
4.1 IDEA configures the local Maven environment (global...)
① Idea uses an external tomcat to run 【Key points】
② Idea uses the built-in tomcat plug-in of maven [understand]
Maven
An introduction to Maven
1.1 What is Maven?
Maven is translated as "expert" and "expert", and it is an open source project developed in pure Java under Apache.
A more formal definition of
Maven is like this: Maven is a project management tool, which includes a project object model, a set of standard collections, a project life cycle, a dependency management system, and the definition used to run the life cycle Tools for plug-in targets in the stage.
1.2 What problems can Maven solve
It can be explained in a more popular way. We know that project development is more than just writing code, it will be accompanied by various essential things to do during the period. Here are a few examples:
1. We need to quote various jar packages, especially for relatively large projects. There are often dozens or even hundreds of jar packages. Each type of jar package needs to be manually imported into the project directory, and often encountered Various jar package conflicts and version conflicts that make people crazy.
2. The java file we have written needs to be compiled into a class file by javac before it can be run by the JVM. This work can be done by a variety of integrated development tools, Eclipse, IDEA, etc. The code can be compiled on the fly.
3. There is no code without bugs in the world, so after writing the code, we have to write some unit tests, and then run them one by one to verify the code quality.
4. In the project, it is often necessary to integrate the code with various configuration files and resources for packaging. If it is a web project, it also needs to be published to the server.
Just imagine, if there is a tool that can free you from the tedious work above, it can help you build projects, manage jar packages, compile code, and can also help you automatically run unit tests, package, generate reports, and even help You deploy the project, generate the Web site, will you be excited? Maven can solve these problems mentioned above.
1.3 Two core functions of Maven [Key]
1.3.1 Dependency Management
How to store jar packages in the warehouse?
1.3.2 Project Construction
Two Maven installation and use
2.1 Maven download and installation
2.2 Maven Warehouse [Key Points]
2.2.1 Classification of Maven Warehouse
2.2.2 Maven local warehouse configuration
Specify a custom local warehouse
2.2.3 Maven warehouse domestic mirror configuration
Modify the setting.xml file in the conf folder under the maven root directory. On the mirrors node, add the following content:
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
2.3 Maven coordinates and dependencies
Which jar package do you want to use only, use the coordinate method to import the dependency...
2.4 Structure of Maven Project [Key Points]
Problems encountered in traditional javaweb projects
Three Maven life cycle and plugins
3.1 Maven commonly used commands and plugins
We can use a series of maven commands in cmd to clean, compile, test, package, install, and deploy our project.
1)clean
The cleanup command of the maven project, executing clean will delete the target directory and content.
2)compile
The compilation command of the maven project is used to compile the files under src/main/java into class files and output them to the target directory.
3)test
The test command of the maven project is used to execute the unit test class under src/test/java and compile it into a class file.
4)package
The packaging command of the maven project is marked as jar package for java project execution package and war package for web project.
Note: Why is maven_hello a war package and not a jar package?
5)install
For the installation command of the maven project, execute install to mark the mave project into a jar package or war package and publish it to the local warehouse.
6)deploy
Maven project deployment command to deploy (upload) the jar or war package to the private server.
3.2 Life cycle
Maven divides the project construction process into "three sets of mutually independent" life cycles. The three life cycles are:
Four IDEA to create a Maven project [key]
4.1 IDEA configures the local Maven environment (global...)
We create a maven project in IDEA to download a skeleton from the Internet by default (but our computer is not connected to the Internet, it will be stuck for a while, and then use the local skeleton), we can directly specify IDEA to find the local skeleton, which improves efficiency
-DarchetypeCatalog=internal -Dfile.encoding=GB2312
4.2 IDEA create project
① java project
Manually create test test configuration file directory
Specify the jdk version and character set of the maven environment
<build>
<plugins>
<!-- 设置编译版本为1.8 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
Maven project command operation
How to import dependencies
Maven search warehouse:<
② Web project [Key points]
Idea creates a web project, we need to install a plug-in
After the installation is successful, restart the idea tool
③ Attention
On some students’ computers, after creating maven, the folder will not change color
4.3 Publish web project
① Idea uses an external tomcat to run 【Key points】
(Same as before)
② Idea uses the built-in tomcat plug-in of maven [understand]
<build>
<plugins>
<!-- 设置编译版本为1.8 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/</path>
<uriEncoding>utf-8</uriEncoding>
</configuration>
</plugin>
</plugins>
</build>
Double-click to start
Command start
4.4 Scope of dependency