Tomcat --- method of creating MavenWeb project

First, use the skeleton to create

The idea provides a project template for MavenWeb projects, which can be directly created using this skeleton

Step 1: Select the web project skeleton and create a project

 

 Step 2: Delete redundant coordinates in pom.xml

After the skeleton is successfully created, we can take a look at the directory. A bunch of useless ones imported in pom.xml can be deleted.

delete to this extent

Step 3: Complete the missing directory structure

The directory structure has been set up through the skeleton, but there are two files missing compared to the normal web project. We need to create java and resource under the main. Right-click to add Directory. Idea will generally intelligently prompt you what is missing, so It is easy to complete the directory structure

Second, do not use the skeleton to build the project

Step 1: Create a project

If you don’t use the skeleton, you just don’t check the skeleton of the web project and create the maven project directly.

Step 2: Add the packaging method to war in pom.xml

The project built at this time is not a web project, because there is no packaging method in the pom file. If not, the default packaging method is jar, so we need to add a packaging method in pom.xml

<packaging>war</packaging>

This is a web project

Step 3: Complete the missing directory structure: webapp

But it lacks the most core directory of the web - webapp, and it can be completed manually. Here we create it automatically, select File, Project Structure

 If there is something wrong with the path after creation, you can drag and drop the file to adjust it

3. Run the project, idea integrates local Tomcat

Just now we created a web project, but if this project is going to run in the future, we have to put it in tomcat. The most primitive way is to pack the project into a war package, and then we find the location of the war package and put it in the corresponding tomcat The deployment of the project is completed under the directory of webapps, but this process is very troublesome, because we need to constantly test when we write code, and it is very troublesome to make a war package and save it to the corresponding location every time we write, so in idae It is very convenient to use tomcat. There are two methods. The first is to integrate the local Tomcat into the idea, and then deploy the project.

first step:

Step 2: Select Tomcat Server Local

 The third step is various configurations and project deployment

Application server selects the installation path of your local Tomcat

 I have already built it here, so there is a war, which should be empty normally, you need to click the plus sign, Artifact

 Click OKtomcat to deploy

4. Use the Tomcat Maven plugin in IDEA

Step 1: Add the Tomcat plug-in to pom.xml. After the coordinates are added, it is equivalent to integrating a built-in Tomcat in your Maven project. Here, the shortcut key can quickly create the template, alt insert and then the option at the beginning of the plugin

 Remember to click refresh in red 

There may be an error at this time

Solution:

Check Use Plugin registry in Setting

 Then restart the idea, click File, select Invalidate Catches and click Invalidate and Restart

Step 2: Use the Maven Helper plugin to quickly start the project, select the project, right click -->Run Maven -->tomcat7:run

or as follows

 In addition, there is another advantage of deploying the project in this way. We can directly specify its port number and path in the xml file, as follows:

 

 

 

Guess you like

Origin blog.csdn.net/weixin_52479225/article/details/127991140