Maven Is a build tool , This build tool can help you better manage package dependencies 、 It can also realize the hot deployment of the project for you 、 And run all the test cases for you 、 You can also package your projects 、 Release 、 It can also realize the multi module construction of the project . This article talks about , How do I understand Maven And use .

Let's talk about it first Maven What can I do , It has the following functions :

1、 Good management of package dependencies in projects .

2、 It can also realize the hot deployment of the project ( The ability to publish projects directly to remote servers ).

3、 Package the project 、 Deploy .

4、 It can also run all test cases .

5、 Realize the multi module construction of the project .

This article , I will take you to build a project , To sum up systematically Maven Knowledge and practical thinking of , I hope it helped you . The content is divided into the following parts :

  • Maven Use

  • Use the command to create a java engineering

  • Project catalog analysis

  • pack

  • Construct a web engineering

  • Maven stay MyEclipse/eclipse On the usage of

  • stay Eclipse To create a Maven Of JAVA engineering

  • stay Eclipse establish Maven Of Web engineering

  • IDEA Use

  • IDEA Use skills

01 Maven Use  

1、 download MAVEN package    

Unzip to the specified directory   G:/maven Under the directory of 

2、 To use the command, first configure the environment variables    

    stay path Quote from 3

3、 test


Enter at the command line  mvn  -version2
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)4
Maven home: G:\maven\apache-maven-3.5.0\bin\..5
Java version: 1.8.0_101, vendor: Oracle Corporation6
Java home: C:\Program Files (x86)\Java\jdk1.8.0_101\jre7
Default locale: zh_CN, platform encoding: GBK8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

4、 Indicating successful configuration .

02 Use the command to create a java engineering

1、 First, create a directory to store the project    

C:\Users\apple\Desktop\maven-project2、 Use the command to enter this directory 

cd /d C:\Users\apple\Desktop\maven-project3、 Use the following command 

mvn archetype:generate    ------> Get the created maven Engineering template 2
This will bring up 2300 Templates for multiple build projects   Selected by default 1311 Template No ( establish JAVA Engineering template )3
direct enter4
Select the version number of the template -------> By default 5
groupId: Group id   This is generally consistent with the main package 6
artifactId: The name of the project is usually written 7
Select the version number :------>  Generally, default is good 8
Write package name  ------> Default and groupId Agreement    Default is good 9
confirm  : Y4、 At this point, if you go to this directory again, you will have a folder for more projects 

03 Project catalog analysis

The directory is parsed as follows :

--------------src                               // The main thing is JAVA   resources    The test file 2
------------------------------------main                //JAVA File and running configuration file 3
------------------------------------------------java          // This one is JAVA Configuration file for 4
------------------------------------test                 // Put the test files and the resources needed for the test 5
-----------------------------------------------java          // The test of JAVA Code 6
---------------POM               // The coordinates of the project itself   Constant   Project dependency packages    Components that the project depends on 

 Project coordinates :

Library dependence :9
   Of the group id12
       Project name 14
       Version number of the project 16
      When is the current library available 18
library :23
    Local library      Remote library 04  pack  
1、 First, use the command to enter the root directory of the project    
mvn package ----------------------> Generate target file 2、 Enter target file 1
Java -jar  MAVEN_01-1.0-SNAPSHOT.jar  The full path of the main class    Run it out
05  structure web Engineering steps   
1、 Enter the directory where the works are stored    
cd /d C:\Users\apple\Desktop\maven-project2、 Get all the templates
mvn archetype:generate3、 choice 1316 Template No  
Input 1316------> The back is the same as the front 4、 Analysis of project catalog    
---------------------------------------------------------java             Deposit java Of documents 4
---------------------------------------------------------webapp          Storage of shared resources 5

Be careful :

Every different type of project is in maven There are different templates in

java The project has java Engineering template

web The project has web Engineering template

Suite The project has suite Engineering template ( Using my father as a project )

06 Maven stay MyEclipse/eclipse Usage of  

1、 download MAVEN stay Eclipse Plug in package on   

2、 Get into window----perfrence---- Input maven

3、installations----add Add local maven Root path

4、 Set local warehouse location and file location    

Be careful :setting.xml The location of the file is under the root path of the local warehouse  setting.xml The configuration file    In fact, this configuration file is not here    It was originally in maven Under the pressure of the road  conf Inside the directory    Then put this file copy To the root path of the library 2
Be careful : The default location of the library is c In the user directory of the disk .m2 In the document    This path can be changed 

07  stay Eclipse To create a maven Of JAVA engineering  

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍1、 Right click ----> newly build

maven engineering ---->Create  a  simple project----> Fill in the project coordinates ( Of the group id、 Project name 、 How to pack (jar)、 Dependent version )----> complete 

2、 Project directory resolution    

rc/main/java: Write JAVA Where to code 2
src/main/resource: This is where the configuration files are stored 3
src/test/java: Where to test the files 4
src/test/resoucre: Where test files are stored 5
target: This is where the packaged files and resources are stored 6
Pom: Deposit is ( Project coordinates 、 Dependency package 、 Dependent component 、 A variety of configurations ) 

3、 Write projects and test them

08  stay Eclipse To create a maven Of Web engineering  

1、 Right click ----> newly build

maven engineering ----->next----->maven archetype webapp( Templates )-----> next step ( Fill in the coordinates of the project )------>finish( complete )

2、 Directory resolution 

----------------------------------------java Resource2
---------------------------------------------------------src/main/resource  : Where resource files are written 3
---------------------------------------------------------src/man/java      : To write JAVA Where to code 4
--------------------------------------------------------webapp: This directory is equivalent to the previous Web-content/Web app Catalog 

3、 Import web Common packages needed for Engineering


<!-- Import our Servlet Of API -->2
    <!-- Import US jstl The package of the tag library  -->10
    <!-- introduce junit class  -->30

4、 Create our jsp file    

<%@ page language="java" contentType="text/html; charset=UTF-8"2
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">4
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">7
<title>Insert title here</title>8
  this is index jsp page12

5、 test ( Right click ---->run on server)

Be careful :

The project created by default is not written JAVA Where to code , So you need to create it manually


In the following src/main Right click above ----->new folder----> Name java  complete    It's on its own 

09 IDEA Use  

1、 Description of the home menu

Create new project : Create a new project 2
  Import project: Import a project (IDEA Project )3
  Open: Open a project 4
  Check out from version control: Represents checking out a project from the repository of version control tools 

2、 Create a java engineering    

Create new project ------- choice maven------ choice create from archetype------next----- Fill in the coordinates of the project 

10 IDEA Use skills  

1、 Set the shortcut key to Eclipse Shortcut keys    

File------setting-----keymap-----> choice Eclipse

2、 Coding settings 

File-----setting----- Input encoding2
File encoding  ----> Select global coding and engineering coding 3、 Font settings   
File------setting----- Input font----- find font----- The font size can be set on the right side
4、 Shortcut key customization 1
File------setting-----Editor----live templates----->  +  -----> add group (bobo1)-----> complete 2
                                        +  ----->live template ----> Input box input    Short for tips ------> stay template text Enter the content to be expressed in 3
Select the created template -----> Right click   Change Context-----> Choose java( It means that java Prompt in the code )----- determine 5、 Change theme
File------------- setting------------------Appearance-------- On the right is the choice of themes ( Choose a theme that suits you )6、IDEA How to install maven 1
File------------setting------------------ Input maven--------> On the right side 7、Tomcat Installation
Run------Edit configrations----- top left corner  +  -----------> find Tomcat server-------->Local----->Application server( Later browsing )------>Configration-----> find Tomcat Root directory -----> complete 

Last words

without doubt , stay Java In ecology ,Maven Is the most popular software project auto build tool . It has replaced Ant For a long time , That's because it's in project management , Dependency management and solutions provide a simpler and declarative model , And it not only has a well-defined build phase ( Such as compiling and testing ), At the same time, it also supports the construction of , Configure and deploy code related plug-ins .

Friendship tips : If you are Maven Novice or inexperienced , So it's better to take some time to learn its basic usage first , Instead of learning through tips and techniques .


If you think that asamura's article will help you , Please search and follow on wechat 「 Shallow feathered IT hut 」 WeChat official account , I'll share my computer information knowledge here 、 Theoretical Technology 、 Tool resources 、 The software is introduced 、 The backend development 、 interview 、 A series of articles, such as thoughts on work and some thoughts on life . What you see and what you get , It's all about life . take your time , Work harder , You and I grew up together ...

I set up a technology group , If you want to know more about IT The technology of the industry and the problems in life , Welcome to join the group , Just add my wechat , Note that you can enter the group , We look forward to your participation .

Previous recommendation

One article for you to understand Spring Basic use of framework


Java What we need to pay attention to in generics


How to be in Java Create elegant objects to improve program performance


More pictures , Understand 8 A common data structure


dried food !MySQL Optimization principle analysis and optimization scheme summary


hardcore !15 Zhang diagram Redis Why so soon?


We media people's essential multi platform synchronization 、 More than one article


Programmer essential technology website Collection


Shallow feather

Message area

Point a praise , Prove that you still love me