directory

Maven

Maven definition

Maven project standard directory structure

Maven installation

Configuring a Local Warehouse

Common commands in Maven

mvn compile

mvn clean

mvn test

mvn package

mvn install

Configure Maven in IDEA

Create a Maven project

How do I use the Maven Tomcat Plugin to run a Web project


 

Maven

Maven definition

A more formal definition of Maven says: Maven is a project management tool that contains a project object model (POM: Project Object Model, a set of standards, a Project Lifecycle, A Dependency Management System and logic to run the plug-in goal defined in the lifecycle phase.

 

Maven’s repositories fall into three categories: local, remote, and central.

Our projects are often compiled, tested, run, packaged, installed, deployed, and so on. What is a build?

  • Maven is used to manage projects from compilation, testing, running, packaging, installation, and deployment

The process is called building. The key to build

  • This refers to the entire build process, which can be done easily with a single maven command.

Maven project standard directory structure

  • SRC /main/ Java directory core code section.
  • SRC /main/resources section of the configuration file.
  • The sr/test/ Java directory tests the code part.
  • SRC /test/resources tests the configuration file.
  • SRC /main/ webApp page resources, JS, Css, images, etc

 

Maven installation

Find the maven website: maven.apache.org/index.html

Then go to the download page

Select a zip package to download

Unzip the downloaded files

File directory

To configure the environment variable, create the MAVEN_HOME environment variable. This is the address of the bin file where you installed Maven

Edit the environment variable Path and append %MAVEN_HOME%\bin;

CMD open the command window and enter MVN -v to check whether the installation is successful

Configuring a Local Warehouse

Open the conf file in maven folder, which contains setting. XML

Under Settings, type <localRepository> your localRepository address </localRepository>

You can download the package of local warehouse on the Internet, or configure the basic package using IDEA

Find Maven Settings. Find Repositories and update local Maven. The diagram below:

 

 

Common commands in Maven

mvn compile

Compile is the maven project compile command, which is used to compile files from SRC /main/ Java into class files and output them to the target directory.

mvn clean

Delete the compiled local information, because everyone’s computer environment is different, so delete the following local information target

mvn test

Compile test code

mvn package

The project package command will pack the project into a WAR package

mvn install

The test code is compiled, and the project is packaged into a WAR package, which is installed into the local repository

 

Configure Maven in IDEA

Open IDEA Setting and find Maven

 

Create a Maven project

You can create a Java folder in the main directory

Turn the Java folder into a resource path

You can change the Java folder to the same resource file format as the WebApp folder

Create a hello.jsp file in the WebApp folder

You can write a servlet in the Java folder

You then need to complete the web.xml file

The servlet package does not exist, so an error is reported in the servlet

The address of the JAR package that you need to import the servlet into pom.xml

Location of jar packages in the local repository

How do I use the Maven Tomcat Plugin to run a Web project

Then run tomcat:run

 

 

 

 

 

 

Learn together and make progress together. If there are any mistakes, please comment