Maven is a build tool that helps you better manage package dependencies, hot deploy your project for you, run all your test cases for you, package your project, publish it, and build multiple modules for your project. This article talks about how I understand and use Maven.

Here’s what Maven does:

**1, ** Well manage package dependencies in the project.

2. It also enables hot deployment of projects (the ability to publish projects directly to remote servers).

3. Package and deploy the project.

4. Also able to run all test cases.

5. Realize multi-module construction of the project.

In this article, I will take you through a project that will systematically summarize the knowledge and practice of Maven and hopefully help you. The content is divided into the following parts:

  • The use of Maven

  • Use commands to create a Java project

  • Project Catalog analysis

  • packaging

  • Build a Web project

  • Maven on MyEclipse/ Eclipse

  • Create Maven’s JAVA project on Eclipse

  • Create Maven’s Web project in Eclipse

  • The IDEA of using

  • Tips on using IDEA

01 Use of Maven

1. Download the MAVEN package

1

Unzip to the specified G:/maven directory

2. To use a command, you must first configure environment variables

1

M2_HOME = G: \ maven \ apache maven — 3.6.0

2

Reference in path

3

%M2_HOME%\bin

3, test,

1

On the cli, enter mvn-version

2

3

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 Corporation

6

Java home: C:\Program Files (x86)\Java\jdk1.8.0_101\jre

7

Default locale: zh_CN, platform encoding: GBK

8

OS name: “Windows 10”, Version: “10.0”, ARCH:” AMD64 “, family: “Windows

4. The configuration is successful.

02 Use commands to create a Java project

1, first create a directory to store the project

1

C:\Users\apple\Desktop\maven-project

2. Enter the directory using the command

1

cd /d C:\Users\apple\Desktop\maven-project

3. Run the following command

1

MVN archetype:generate ——> Get the template for the Maven project you created

2

There are more than 2300 templates for the build project. The default is template 1311 (the template to create the JAVA project).

3

Directly enter

4

Select the template version ——-> Default

5

GroupId: groupId this is generally consistent with the main package

6

ArtifactId: This usually writes the project name of the project

7

Select the version number: ——> General default is good

8

Write package name ——> default and groupId default is good

9

Confirmed: Y

4, at this time to look at the directory will be one more project folder

03 Project Directory Parsing

Directory resolution is as follows:

1

————– SRC // mainly put the JAVA resource test file

2

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — – the main / / JAVA file and run the configuration file

3

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — Java / / this is the Java configuration file

4

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — – the test / / put the test file and test resources you need

5

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — Java / / testing Java code

6

—————POM // Coordinates constants of the project itself dependencies of the project components that the project depends on

Project Coordinates:

1

com.qy.shopping

2

MAVEN_01

3

1.0 the SNAPSHOT

4

jar

5

6

MAVEN_01

7

www.example.com

8

Library dependencies:

9

10

11

Set the id of the

12

junit

13

Project name

14

junit

15

The version number of the project

16

4.11

17

When is the current library available

18

test

19

20

21

22

Library:

23

Local library Remote library

04 packaging

1. Enter the root directory of the project using the command

1

C:\Users\apple\Desktop\maven-project\MAVEN_01\

2

MVN package ———————-> Generate the target file

2. Access the target file

1

Java-jar maven_01-1.0-snapshot. jar the full path of the main class is run

05 Web Engineering Procedure

1. Go to the directory storing the project

1

cd /d C:\Users\apple\Desktop\maven-project

2. Get all templates

1

mvn archetype:generate

3. Select template 1316

1

Type 1316——> The following is the same as the preceding

4. Analysis of project catalog

1

——————————-src

2

——————————————-main

3

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — Java Java file storage

4

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — a webapp deposit foreign Shared resources

5

——————————-pom

Note:

Each different type of project corresponds to a different template in Maven

Java Projects have templates for Java projects

The Web project has a template for the Web project

Suite project has Suite project template (used as a parent project)

Maven in MyEclipse/ Eclipse

1. Download the MAVEN plugin package on Eclipse

2. Go to Window —-perfrence—- and enter Maven

* The local root path of Maven is added to the * * —-add

4, set the local warehouse location and set the file location

1

Note: the setting. XML file is located in the root directory of the local repository. The configuration file is not actually in the conf directory of maven

2

Note: the default location of the library is the. M2 file in the user directory on drive C. This path can be changed

Create maven’s JAVA project on Eclipse

1. Right-click —-> New

1

Maven project—-> Create a simple project—-> fill in the project coordinates (group ID, project name, packaging method (JAR), dependent version)—-> done

2. Project directory resolution

1

Rc /main/ Java: Where Java code is written

2

SRC /main/resource: This is where the configuration files are stored

3

SRC /test/ Java: where to test the file

4

SRC /test/resoucre: where the test file is stored

5

Target: This is where packaged files and resources are stored

6

Pom: Holds (project coordinates, dependency packages, dependent components, various configurations)

3. Write projects and test them

08 Create Maven’s Web project on Eclipse

1. Right-click —-> New

1

Maven project — — — — — > next — — — — — > maven archetype webapp (template) — — — — – > the next (fill in the coordinates of the project) — — — — — – > finish (finish)

2. Directory parsing

1

—————————————-java Resource

2

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — SRC/main/resource: write a resource file

3

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — the SRC/man/Java: writing Java code

4

—————————————src/main

5

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — – a webapp: this directory is equivalent to the previous Web content/Web app directory

3. Import common packages required by web projects

1

2

3

javax.servlet

4

javax.servlet-api

5

3.1.0

6

provided

7

8

9

10

11

javax.servlet.jsp.jstl

12

javax.servlet.jsp.jstl-api

13

1.2.1

14

15

16

17

javax.servlet

18

jsp-api

19

2.0

20

provided

21

22

23

24

org.apache.taglibs

25

taglibs-standard-impl

26

1.2.5

27

28

29

30

31

junit

32

junit

33

4.12

34

test

35

4. Create our JSP file

1

<%@ page language=”java” contentType=”text/html; charset=UTF-8″

2

pageEncoding=”UTF-8″%>

3

4

5

6

7

8

9

10

11

this is index jsp page

12

13

14

5, test (right-click —-> Run on server)

Note:

The project created by default has no place to write JAVA code, so it needs to be created manually

1

Right click —–> New Folder —- in the SRC /main directory below

09 Using IDEA

1. Description of menu on home page

1

Create new Project: Create a new project

2

Import project: Import a project (IDEA)

3

Open: To Open a project

4

Check out from Version Control: Indicates that an item is checked out from the repository of the version control tool

2. Create a Java project

1

Create New Project ——- Select Maven —— select Create from Archetype ——next—– Fill in the project coordinates

10 Skills of using IDEA

1. Set the shortcut key to Eclipse

1

The File — — — — — – setting — — — — — keymap — — — — — > select Eclipse

2. Coding Settings

1

The File — — — — — setting — — — — — input encoding

2

3

File encoding —-> Select global encoding and project encoding

3, font Settings

1

File — — — — — – setting — — — — — input the font – find the font – you can set the font size on the right side

4, shortcut key customization

1

File — — — — — – setting – Editor – live templates — — — — — — — — — – > > + add group (bobo1) — — — — – > to complete

2

+ —–>live Template —-> input field short for the prompt ——> Enter what to express in template text

3

4

Select the created template —–> right-click Change Context—–> select Java (which means prompt in Java code)—– ok

5. Change the theme

1

File — — — — — — — — — — — — — setting — — — — — — — — — — — — — — — — — — the Appearance — — — — — — — — the right there is the choice of topic, choose to suit their own theme)

6, IDEA how to install Maven

1

The File — — — — — — — — — — — — setting — — — — — — — — — — — — — — — — — — input maven — — — — — — — — > configured on the right side

7. Installation of Tomcat

1

Run — — — — — – Edit configrations the top left corner + — — — — — — — — — — — — — — — — > find Tomcat server — — — — — — — – > Local — — — — — > Application At the back of the server (browse) — — — — — – > Configration — — — — — > to find the root of the Tomcat — — — — — > to complete

The last word

Without a doubt, Maven is the most popular automated build tool for software projects in the Java ecosystem. It has long replaced Ant, thanks to its simpler and declarative model for project management, dependency management, and solutions, as well as its well-defined build phases (such as compile and test) and support for numerous plug-ins related to building, configuring, and deploying code.

A word of caution: If you are new to or inexperienced with Maven, it is best to take the time to learn the basics, rather than using tips and tricks.

“Like” to prove you still love me