Use IDEA to create a project under maven

1. Create a parent project

1. Create Project
insert image description here
insert image description here

2. Turn on the automatic import function (IDEA2020 cancels this setting)

  • Method 1: shortcut key method
    Use Ctrl + Shift + O to automatically import maven dependencies.
  • Method 2: Click on the icon. Every time a new dependency is added, there will be a small M icon in the upper right corner of pom.xml. Click to load Maven changes.
    insert image description here
    3. Configure Maven information
    insert image description here

2. Create a JAVA module project

insert image description here

insert image description here
Add junit dependency
insert image description here
test:

  • Create a new Java file in main
    insert image description here
  • Create a new test file in test and run it successfully
    insert image description here

3. Create a web module project

1. Follow the steps to create a java module to complete the creation.
2. Modify the packaging method
insert image description here
3. Web settings
insert image description here
insert image description here
insert image description here
Note that you need to add src/main to the directory
Generate web.xml with IDEA
to set the root directory of the web resource
insert image description here
to generate the web directory:
insert image description here

Note: You can also add the web directory through Add Frameworks Support:
insert image description here
insert image description here
but the generated web directory is not under the main, you need to manually set it:
first pull the web directory directly under the main, and then set the root directory:
insert image description here
insert image description here
4. Create a new Tomcat connection
insert image description here

insert image description here
insert image description here

insert image description here
insert image description here
The browser appears:
insert image description here

The point is to set the root directory of the web! ! ! !

Flowers are over!

Guess you like

Origin blog.csdn.net/Mason_Chen/article/details/126804408