1. Brief introduction to Maven
1. Maven is a project management tool that includes a Project Object Model, a set of standards, a Project Lifecycle, a Dependency Management System, and a Define the logic of plugin goals in life cycle phases. When you use Maven, you describe your project with a well-defined project object model, and Maven can then apply cross-cutting logic from a set of shared (or custom) plugins.
2. Maven has a life cycle, which is called when you run mvn install. This command tells Maven to execute a series of ordered steps until the life cycle you specify is reached. One effect of the journey through the lifecycle is that Maven runs a number of default plug-in goals that do things like compile and create a JAR file. In addition, Maven can easily help you manage project reports, generate sites, manage JAR files, etc.
2. Commonly used commands
mvn archetype:generate Create a Maven project
mvn compile Compile the source code
mvn deploy Release the project
mvn test-compile Compile the test source code
mvn test Run unit tests in the application
mvn site Generate a website for project related information
mvn clean Clear the generated results in the project directory
mvn package jar generated based on the project
mvn install Install the jar in the local Repository
mvn eclipse:eclipse Generate the eclipse project file
mvnjetty:run Start the jetty service
mvntomcat:run Start the tomcat service
mvn clean package -Dmaven.test.skip=true: Clear the previous Repackage after packaging, skipping the test class
mvn dependency:tree -Dverbose -Dincludes=asm:asm Query the dependency tree structure of the package
3. Maven advantages
1. When the project is very large, you can use Maven to split a project into multiple projects. It is best to have one module corresponding to one project, which facilitates division of labor and collaboration. And messages can still be sent between modules.
2. With the help of Maven, the jar package can only be saved in the "warehouse". When the file is needed, the file interface can be referenced without copying the file to occupy space.
3. With Maven, you can download jar packages in a standardized way, because the jar packages of all well-known frameworks or third-party tools have been stored in Maven's central warehouse according to unified specifications.
4. Maven will automatically import the jar package you want to add to the project, not only importing it, but also automatically importing the jar packages that the jar package depends on.
4. Download and install
1. Official website download
Download address: maven official website download
Pull down the page to find archives (archives) and click
to select the version, I chose 3.6.3 here
Then select binaries (binary files)
to download the installation package
2. Maven installation
Unzip the downloaded file to the specified directory
5.maven configuration
1. Open the advanced system settings interface.
Right-click My Computer => Properties => Advanced System Settings. Click
Environment Variables.
2. Create a new MAVEN_HOME variable in the system variables, set the variable name and variable value,
and check whether there is a newly added variable
. 3. Add Configure MAVEN_HOME to the system environment variable path.
Double-click the path variable, create a new parameter, enter %MAVEN_HOME%\bin and click OK.
%MAVEN_HOME%\bin
4. Check whether the installation and configuration are successful.
Win+r opens the run interface, enter cmd to open the command window.
Type mvn -version in the cmd window and press Enter. If the following version number appears, it means that the maven configuration is successful.
6.setting file configuration
1. Create a folder in a disk and name it maven_repository (you can customize the name according to your own habits). It is best not to choose the c drive, because it takes up a lot of memory and affects the operation of the computer.
2. Open the maven installation directory and select the setting.xml file in the conf folder.
3. Modify the file settings.xml
to find the localRepository configuration in settings.xml and modify it to the directory of the folder you just created. Pay attention to moving D:\maven_repository out of the comments!
Note: Note that the moved position is outside the comment.
4. Check whether the setting has been successful.
Enter mvn help:system
on the console and BUILD SUCCESS will appear, indicating that the execution is successful.
Check whether there is already a related folder "org"
. Find the newly created maven_repository folder and check inside. Is there an "org" folder
? If files are generated in it, it means the modification is successful.
5. Modify the Maven download image address to Alibaba source.
After installing Maven, you must promptly modify the Maven download image address. It is best to change it to a domestic download image, such as Alibaba Cloud Central Warehouse, Huawei Cloud Central Warehouse.
What is added here is the Alibaba Cloud central image
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
7. Development tool configuration Maven
1. Idea configures maven.
Open idea=》File=>Settings…=>Build, Execution, Deployment=>Build Tool=>maven
for configuration.
The above is the whole process, I hope it is useful to you, thank you for reading! ! !