Maven project management tool basic introduction series (2)

I. Introduction

In this article, the basics of Maven project management tools (1) , we have had a preliminary understanding of Maven and the benefits of using Maven as a project management tool, especially how to quickly build Web projects through Maven, but last time Some students said that the web project built through the previous article did not find the web.xml file, because the skeleton was not skipped.

Yes, if you create a Maven project without skipping the skeleton, you need to manually set the template of the Web project yourself. This is relatively complicated in Eclipse, but developing in IDEA has become very simple. The last step in the program is to create the Web template.

Therefore, when we create Maven projects, we usually skip the skeleton directly, so some students asked, what is a skeleton? To put it simply, skipping the skeleton is to directly create a web template. After creating the template, you don't need to manually set it up. If you still don't understand, you can contact me in the background of the public account, and I won't go into details here.

We already know that we can develop Java projects after quickly creating a Maven program through IDEA. Aside from the question of whether the project has been developed, how do we compile and run Maven to manage Java projects? This is the main content of this article: the common commands of Maven.

2. Common commands of Maven in the command line

Here we first explain how to compile, run, package and test the Maven project in the command line window, and we will also talk about the operation of the Maven project in IDEA later.

1. Compile the files in the main directory: compile

Enter the main directory of the Maven project from the command line, and execute the following command to quickly compile the project. After compilation, a target directory will be generated in the main directory to store the compiled files:

mvn compile

as the picture shows:

2. Clear the compiled files in the home directory: clean

Enter the main directory of the Maven project from the command line, and execute the following command to clear the compiled project, and the previously generated target directory will also be cleared:

mvn clean

as the picture shows:

3. Compile and run the code in the test directory: test

Enter the main directory of the Maven project from the command line and execute the following command to clear the compile and run test directory:

mvn test

as the picture shows:

4. Packaging project: package

Enter the main directory of the Maven project from the command line, and execute the following command to package the project. The result shows that BUILD SUCCESS indicates that the project is packaged successfully, and the packaged project can be found in the target directory under the main directory:

mvn package

as the picture shows:

5. Publish the project to the local warehouse: install

Enter the main directory of the Maven project from the command line, and execute the following command to publish the project. The result shows that BUILD SUCCESS indicates that the project was successfully published. The packaged project can be found in the local warehouse:

mvn install

as the picture shows:

6. Start the Maven project with one click in the Tomcat container:

The command line executes the following commands:

Tomcat:run

3. Compile, publish, package and test Maven projects in IDEA

Compiling, clearing, publishing, packaging, and testing Maven projects in IDEA is very simple, and it is all done with one click. After creating your own project, click the Maven Project option on the right side of IDEA, click your own project name in the pop-up window, and you will see the common Maven commands we mentioned above, just double-click to complete, As shown below:

Scan the QR code and follow the WeChat public account to learn more

--------------------------------------------

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324611389&siteId=291194637