1. Set the location of maven specified in the idea and the local storage warehouse
In development, we generally use the maven downloaded by ourselves instead of the IDEA tool. This requires configuring the maven we downloaded into the IDEA tool, as shown in the following figure:
Or direct shortcut key Ctrl+Alt+S to directly enter the settings
maven home path: Fill in the location of the maven you downloaded (mine is placed on the D drive)
user setting file: It is the settings.xml file used to configure where to download the dependent jar package
Local repository: is the local repository path where the downloaded jar package is stored
The next step is to use a text editor to open the conf >settings under the maven file you downloaded
In this position, according to this website, change the maven source to the domestic Alibaba cloud mirror to modify the website, otherwise the subsequent download dependencies will be very slow
In the following location, modify its default local warehouse
2. New project
2.1 Create a maven project for a web project according to the template
The above selection is the template for developing web projects. You can search for templates that can be selected for developing different projects on Baidu.
Click create to create a maven template for a web project. Of course, it takes a certain amount of time to form the maven skeleton.
The directory structure at this time after waiting for a certain period of time:
It is necessary to complete two folders java and resorces under the main folder. How to add them is described below
The following is the standard directory of maven projects:
src/main/java
src/main/resources
src/test/java
src/test/resources
Let's build the directory, right-click New->Directory on main to create a new java folder and resources folder
Right-click New->Directory on the src directory to create a new test folder
Right-click New->Directory on the test directory to create a new java and resources folder
The next step is to associate the newly created folder, and see the red associated objects clearly. If the association is wrong, it must be re-associated. This must not be wrong. The association method is as shown in the figure below.
src/main/ java is associated as Sources Root
(Right click on java "select mark Directory as" select Sources Root)
src/main/ resources is associated as Resources Root
(Right click on resources "select mark Directory as" select Resources Root)
src/test/ java is associated as Test Sources Root
(Right-click test under the test folder "select mark Directory as" select Test Sources Root)
src/test/ resources is associated as Test Resources Root
(Right-click resources under the test folder "select mark Directory as" select Test Resources Root)
Directory structure after creation:
This creates a maven project
2.2 Create a maven project for a web project without a template
Click create, as follows
It can be seen from the left that the web project lacks some corresponding project folders, and then manually complete these folders
First right-click the test folder to create a resources ordinary folder, and then as follows
Next, you can create an empty directory webapp under main as the web directory
Click the file in IDEA to open the project structure in the options, and add web framework to maven
Click ok, this item web.xml is created, and then specify the location of webapp
Note: Do not click ok first, then click the Artifacts option on the left, as shown in the figure below to create a war-based startup item for the project
Click ok in the pop-up box, then click apply below, and ok is enough. This prevents that there may be no war mode startup item in tomcat configuration when running the project. After completing the above
Next, you can see that all the folders are completed, as shown below:
In this way, the above steps can be completed without using the template to create the maven of the web project. Of course, you also need to create an index.jsp file under the webapp. The next step is to run it simply.
3. Run the project
Deploy your own Tomcat in Idea and perform
Idea has built-in Tomcat, depending on individual needs, if you want to configure Tomcat, you can configure it. If you don’t want to configure Tomcat, you can use the Tomcat that comes with the development tool. The following steps: Configure tomcat installed on your computer (1). Enter Idea directly
, Click Run——Edit Configurations...
(2) Click the "+" sign on the left to find Tomcat Server——Local (if Tomcat Server is not found, you can click the last line 34 items more)
Successfully run interface
The above is to deploy the maven project in Idea (using tomcat installed on your own computer)
Another way to deploy
Install the Maven Help plug-in first, and use the tomcat that comes with maven to start the project. This method will be introduced next time