I. Introduction to Maven
Maven is an open source project under Apache. It belongs to pure Java development, and is only used to manage Java projects. It is a project management tool, using Maven to build and dependency management Java projects. Project construction refers to the process of project coding, compilation, testing, running, packaging, deployment, etc. Dependency management refers to the unified management of JAR packages required by the project.
Maven is also a very popular and useful project management tool, and the number of projects managed using Maven continues to grow.
Why use Maven
We know that traditional project development requires the import of specific JAR packages into the process, which obviously increases the size of the project. However, Maven has a remote repository dedicated to storing JAR packages, including various versions of jar packages, for project dependency management. The biggest feature is the ability to significantly reduce the size of projects.
For example, the size of the project developed by using the traditional jar package import method is 50M, while the size of the project developed by using Maven dependency management may be less than 2M. Therefore, using Maven for project management can manage the JAR package in a unified manner and save space.
Furthermore, Maven modules development, such as the Web layer, service layer, DAO layer module development, and the project can be one-click construction, obviously this can improve the efficiency of development.
Download and install Maven
I believe that download and installation for everyone is no problem, here is a simple talk on the line.
1, download
Maven is available for download from the official website of Maven
2, installation,
Decompress the downloaded file directly. Ensure that the folder name cannot contain the space bar. Otherwise, problems may occur in future use.
After the decompression, configure the Maven environment on the computer. Open the system variable configuration window of environment variables, create a MAVEN_HOME environment variable, and set the value of the variable to the decompression directory of Maven. I believe everyone here can complete the configuration, if it is really unable to complete the configuration, you can also contact me to the public background.
The JDK must be installed on your computer before you can use Maven, and the JDK version requirements are different for different Maven versions. However, there is no problem with JDK 1.7.
The last step is to verify whether the Maven environment is configured successfully. Because Maven will run the MVN command in the bin directory of Maven installation directory, the local win + R directly open the CMD command window, and run the following command to check whether the configuration is successful:
mvn -v
Copy the code
The results are shown below:
Maven warehouse
Earlier, we talked about the space savings of using Maven for project management mainly because Maven centrally manages jar packages, which are stored in a repository.
Maven has three repositories:
- Local warehouse: a self-maintained warehouse
- Remote warehouses: Some companies maintain them
- Central repository: Maintained by the Maven team
The relationship between these three warehouses is shown in the figure below:
We do not have the authority to manage remote warehouse and central warehouse, but we have the authority to set up local warehouse. To configure the local repository, you only need to modify settings. XML in the conf folder of the installation directory to customize your own local repository, as shown below:
Getting started with Maven
1. Open the IDEA new Maven project and click Next to enter the Next step, as shown below:
GroupId is the structure of the Java package, is the Java directory structure in the main directory, and ArifactId is the name of the project, which is the name of the root directory of the project. After filling in, click Next to proceed to the Next step. As shown below:
3. Fill in the working section for storing the project and click Finish, as shown below:
4. After the Maven project is created, it will directly open the most important configuration file of Maven project pom.xml, which will be explained in detail later, as shown in the following figure:
5, Manually create the Maven template, select the Project, click The Project Structure under File, select Modules, click the + symbol, and then add the Web template. Other templates can be left unchanged for the time being, as shown in the picture:
Maven configuration file details
Open all the project folders. Here, only the main Maven project files are explained, as shown below:
Pom.xml: The core file of the Maven project, used to configure dependent JAR packages
Main: The home directory of the Maven project
Java: Holds all the Java code files for the project
Resources: Stores the Properties resource file and XML configuration file
Webapp: Store static resource files and page files
Test: test directory for storing junit test files
Yes, here is the basic can carry out Java project development, specific how to develop, the later will continue to update, keep paying attention to it.