maven project management tool

Keywords: Front-end Maven


A series of materials I publish are my study, backup and use, and convenient for future review. With my continuous improvement, each article will continue to add content or expand the article, so the article I publish will be relatively long. If you brush my article, it will be helpful to you and can be collected

Enterprise architecture

Frame diagram

Before, we focused on the front-end solutions (technologies involved include H5, CSS3 and JavaScript, CSS upgraded to Bootstrap and then upgraded to ElementUI, JavaScript upgraded to jQuery and then upgraded to Vue+NodeJS). Now we start to focus on the back-end solutions, that is, what the server does and what technologies support it (SpringBoot, Maven, SpringMVC, Spring, Mybatis). In this way, after learning the front and back ends, the basic technologies required for the whole software project will be fully connected, and you can independently complete the development of enterprise projects.

Let's describe a classic business request process: the front-end html page initiates an ajax request( http://localhost:8080/factoryController/findAll ) , access the Controller control layer of the Spring MVC framework. The Spring MVC framework parses the request, finds a Controller to be called, finds the findall method, and encapsulates the parameters submitted by the request into a java object. Then, the Controller layer passes the request to the Service business layer of the Spring framework, and the Service layer passes the request to the Mapper persistence layer of the Mybatis framework Ask the MySQL database to query the database table. The query results are returned to Mapper layer, Mapper layer and Service layer, and then the Controller layer. The Controller converts the java data into json string and returns it to ajax call. ajax calls back and converts the json string into js object. Then the js object can be parsed through js/vue in the page, and finally the data is displayed to H html page.

  • Development tools: the front end uses HBuilderX, while the back end uses eclipse/idea
  • Project management: the front end adopts npm and webpack, while the back end adopts Maven and SpringBoot
  • web middleware: the front end uses NodeJS and the back end uses Tomcat

Maven project build tool


Maven is a cross platform project management tool. As a quite successful open source project in Apache organization, Maven mainly serves project construction, dependency management and project information management based on java platform. Maven can play a great role in small open source class library projects, large enterprise applications, traditional waterfall development and popular agile model .

Why maven?

In the Java project, we find jars by ourselves, either from the official website, or from netizens, or from the project team. In any way, we need to copy the jar file to the lib directory and build path.

Maven changed this way of manually maintaining jars and designed a set of automatic jar maintenance system, which has been widely used in software projects. It is a technology that software developers must master.

New design system: the pom Model invented by Chuangxian River introduces "warehouse", "dependency", "coordinate" and "command".

Four characteristics

Warehouse repository

Maven is very similar to git we learned before. It is also a distributed architecture. It has a global warehouse, called the central warehouse. Global developers can connect to it to automatically download jar packages without going to the manufacturer's official website. They all go to a central warehouse to download. The central warehouse is under great pressure, so there are image warehouses all over the world, such as Netease, Alibaba and so on Warehouse. But every time you go to the Internet to download, it won't be a day to pay the network fee. Maven certainly won't do that. It also has a local warehouse. After downloading once, it won't download again unless you delete it.

When a user needs a jar package, he first goes to the local warehouse to find it instead of the image warehouse or the central warehouse. After the central warehouse is found, he does not directly return to the local warehouse, but saves a copy to the image warehouse. The image warehouse returns to the local warehouse, and the local warehouse also saves a copy, and then returns it to the caller. Is this design too subtle and only needs maintenance Central warehouse and other warehouses maintain themselves. This is the charm of maven. This design idea needs to be pondered and used for reference by our developers.

Because of its full automation, the central warehouse defaults, and the mirror warehouse needs to be configured without writing a sentence of code.

The warehouse only solves where jars come from and where they are placed. There are thousands of jar packages. We have jdbc drivers, junit unit tests, spring framework, mybatis, etc. How can we call our project?


Each core jar package forms a dependency, and maven bottom layer automatically imports its related jars



Why should there be coordinates? What is the essence of coordinates?

Maven world has a large number of builds. We need to find a unified specification to uniquely identify a build. With a unified specification, we can hand over the search to the machine and find the jar package by default.

How do you feel after reading it? It's not clear yet? Coordinates are not to form a set of file storage rules, so that jar packages from different manufacturers around the world can be saved in maven warehouse without conflict and in their own directories. Even if their own versions are placed in different directories because of different version numbers, they will not cause conflict at home.

At the same time, the most important thing is that with a unified specification and a unique name, you can automatically find the required jar package.

This design level can be seen. A set of directory rules makes jar automatic processing a reality.

Command mvn cmd

Next, there is a great design, which is worth tasting. Maven has defined a set of life cycles based on his predecessors. There are three life cycles: clean, default and site. Each life cycle contains multiple phase s. This is not surprising, but the next is the powerful place.

Common commands:

  • clean cleanup
  • Compile compile
  • Test test
  • Site site documentation
  • Package package jar and war
  • deploy to private server
  • Install install the jar into the local repository
  • Run run
    When a command is run in each cycle, other phase steps in the cycle before the command will be executed. For example, executing install will automatically execute compile (compiling java into class), test (running all unit test classes), and package (packaging the fragmented class files of the whole project into jar packages) Finally, the finished jar will be released to the local warehouse, but the clean will not be executed automatically by executing install.

What does this mean? Look at the following command:

mvn compile,

mvn compile,test

mvn compile,test,package

mvn compile,test,package,install

This means that many commands are executed at once, also known as one click deployment, and this process is fully automatic. Previous developers did every step by themselves.

You can also execute multiple commands at once, and each command executes the commands in front of it:

mvn clean install

Note: these maven commands can be executed directly in the dos window, but the system variable maven needs to be configured_ Home, but in actual development, we often integrate with the development IDE environment, and rarely directly use dos mvn command, which will not be introduced here.



  • Jar is easier to manage and has been widely used in the industry. springboot is an extension of maven
  • The unique design of the warehouse enables the warehouse to maintain itself
  • Dependency management is much more convenient, freeing developers from manual package guidance
  • The coordinate system enables the files of different manufacturers to be in order without conflict and overwrite
  • The life cycle corresponds to the command to complete the previous manual n steps with one click


  • Download exceptions make beginners at a loss. They have to delete the warehouse and download it again. Why? I don't know
  • Some packages need to be imported manually because of version problems
  • Cause new problems and version conflicts: in large projects, jars rely on other jar packages, which will cause the notorious version conflicts when you adjust 3.1 and I adjust 3.2. How to solve them? The above method is manual exclusion, while maven adopts the principle of proximity
  • The local warehouse is huge day by day. My own has reached 2g. Many lower versions of jars are useless or outdated technology jars
  • Jar conflicts in large projects are very serious and still need to be eliminated manually. There are many implementation methods and there are no unified rules. For example, when I joined dubbo's jar, the conflict was called flying all over the sky, and the project was not well solved. However, springboot has solved this problem. The failure of maven has long been the root cause of the popularity of springboot today.


Official website:

Configure settings.xml

Find the settings.xml in the conf folder in the maven installation location

Set up mirror warehouse

It is downloaded from maven's official website by default. It is downloaded all over the world. It is also a foreign website, so the speed is slow.

It is configured as an Alibaba image, which is fast, but sometimes there are errors. If there are errors, delete the configuration and download it from the maven official website by default. Configure the Alibaba private server image warehouse, which can be written in the middle of the mirrors tab: about 160 lines

<!--Ali private server address-->
	<name>ali Maven</name>

Change warehouse location

Default warehouse location: C:\Users\lpx.m2. It is recommended to change the configuration of the default warehouse location, otherwise the warehouse may be deleted by mistake when reinstalling the operating system.

eclipse integration maven

to configure

Maven is very powerful, and major development tools are directly integrated with ides, and eclipse is no exception. Enter the preferences menu of eclipse, select maven, and check "Download Artifact Sources". When downloading the jar package, it will automatically download the source code of the device, which is a very considerate function for developers to view the source code.

By default, Eclipse has integrated maven (EMBEDDED), but we basically don't use it. It is said that there are problems. We are used to downloading the latest version of maven and configuring it ourselves.

Select the root directory where maven is installed. Don't forget to check it.

Creating Maven projects with eclipse

Create maven project

Project directory structure

Maven advocates a slogan: agreement is better than configuration!

convention over configuration, also known as programming by convention, is a software design paradigm, which aims to reduce the number of decisions that software developers need to make and obtain simple benefits without failure.

Put the project code under main, the test code under test, the source code file under java, and the resource file under resources. The project code management structure is clear, the division of labor is clear, and each belongs to its own position, which is easy to manage and finally facilitate the automation of the program. The Maven command can be executed with one click, and its core point depends on this. This is true for Maven and Spring/SpringBoot.

Note: the archetype s of Maven's individual skeletons will not create the above directories completely, and the creation of each skeleton is slightly different. There are many bug s, which doesn't matter. We can create and supplement them manually.

IDEA integration maven

IDEA create maven project

Add dependent package

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""

    <!--  add to mysql Dependency. Multiple dependencies can be supported. Dependencies are represented by coordinates -->
            <!--To match the database version,
            The database is 5.X Add 5 to the version of.X Dependence of
            The database is 8.X Add 8 to the version of.X Dependence of

common problem

Search for maven dependent coordinates

Query the latest version and coordinates

Memory overflow while executing maven command

When using maven, if memory overflow is reported, for example, using mvn site will consume a lot of memory, modify the default configuration.


stay@REM set MAVEN\_OPTS=......Later join

set MAVEN\_OPTS= -Xms128m -Xmx512m

Copyright causes jar s not to be in the remote repository

For example, oracle, IKAnalyzer for full-text retrieval, word splitter, Dubbox, etc.

Solution: manually create the directory structure according to maven coordinates, download the jar separately and put it into it

Download interrupted

Remote warehouse is not only a foreign website, but also a target of public criticism. Where can I download it all over the world. Incomplete jar download is often caused by network failure:

jsp-api-2.1.jar.lastUpdated   --It is not fully downloaded and cannot be used. An error will be reported when using it
mysql-connector-java-5.1.48.jar –download OK of,Before you can use it

In this case:

  • You can wait until the network is better
  • You can copy other people's warehouses
  • If there are only individual jar packages, you can download them from the official website of jar and configure them manually

In the worst case, an exception is downloaded, that is, pom.xml will prompt that there is a problem with the jar package. You can go to the maven local warehouse and the jar also exists. At this time, you can open the jar package to see if it can be opened. If it cannot be opened, it will be deleted and maven will be triggered to download again.

Avoid downloading so many jar s online

Note: maven is different from myeclipse/eclipse, and the maven plug-in of myclipse will call different versions of jar. There will be no lack of jars for business use.

The Maven command is actually a jar package. Before running, you must download the Maven plug-in. If it does not exist, it will be downloaded automatically.

Maven warehouse is the best way to live or die

Copy the configuration files and warehouses of students who have no problem with the environment.

Version number sharing

Usually, in a project, we will rely on different modules of the same component at the same time, such as spring-orm-3.2.0 and spring-context-3.2.0, and multiple modules have the same version. In order to facilitate maintenance and upgrade, we can manage them at the same time. At this time, we can use Maven attribute, which is similar to the concept of variable.

<!-- Centralized definition dependent version number -->

<!--Place of reference -->
</dependency>Command plug-in

For one click deployment, executing each command will automatically call the previous command. You can perform multiple naming at once. Only the previous commands in this lifecycle can be executed.

Each Maven command is a jar, a maven plug-in. Download on first run.

settings.xml file

<?xml version="1.0" encoding="UTF-8"?>

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

 | This is the configuration file for Maven. It can be specified at two levels:
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |                 NOTE: This location can be overridden with the CLI option:
 |                 -s /path/to/user/settings.xml
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |                 NOTE: This location can be overridden with the CLI option:
 |                 -gs /path/to/global/settings.xml
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
<settings xmlns=""
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   | Default: ${user.home}/.m2/repository 

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   | Default: true

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   | Default: false

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.

    <!-- Another sample, using keys to authenticate.
      <passphrase>optional; leave empty if not used.</passphrase>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
      <name>Human Readable Name for this Mirror.</name>
      <!-- Dane private server address -->
		<name>Tedu Maven</name>

	<!--Ali private server address-->
		<name>ali Maven</name>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.


          <name>Repository for JDK 1.4 builds</name>

     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.



  <!-- activeProfiles
   | List of profiles that are active for all builds.

Posted by webster08 on Wed, 01 Dec 2021 19:34:08 -0800