Application of Maven in IDEA
Article directory
- Application of Maven in IDEA
3.1 IDEA integrates Maven
There is a built-in maven in idea, but the built-in one is generally not applicable, because it is inconvenient to modify the maven configuration with the built-in maven. To use maven installed by yourself, you need to override the default settings in idea. Let idea know about the maven installation.
There are two places to configure: File-settings
andFile-other settings
The configuration in settings is for the currently opened project, and the other settings are for the newly created project. So both places have to be configured.
If not File-other settings
, it File - New Project Settings
can be found in .
3.1.1 settings settings
The following is a description of the settings in the settings:
After entering the maven interface, we need to configure the following three pieces of information:
- Maven home path: maven installation directory
- User settings file: files in the maven installation
conf/settings.xml
directory - Local repository: local repository location
First is the Maven home path:
Then set the settings.file:
If the Local repository is wrong, it can also be modified.
Then we make two modifications under Maven-Runner:
-DarchetypeCatalog=internal
: When maven creates a project, it will download the template file online, which is relatively large. If you use this option, you don't need to download it and create a maven project block.- Set JDK version
- For new project settings, the setting methods and steps are basically the same as the above settings, and will not be repeated here.
When you create a new project, the following settings will take effect.
3.2 IDEA creates a Maven version of the Java project
3.2.1 Creating a project using a template
First we create an empty project and create a new module under the project:
The template we choose is: maven - archetyoe - quickstart
, which represents the template of a common java project.
Then click next to go to the next step.
Then enter the coordinates to fill in:
Finish is over.
But there is no resources directory under main. This is because the template we selected does not have it, so if necessary, create a resources directory in the new directory of idea. Then select the newly created resources directory, right-click, and select Make directory as
Further to Resources Root
complete the settings.
Next, we also set the resources directory under test. After the setting is completed, it is the complete directory structure:
3.2.2 Creation of test classes
To run the Test method, you can directly select the corresponding running interface:
Using the maven tool window in idea, we can get the effect of the previous common maven commands.
3.3 IDEA creates a Maven version web project
First, we create a new maven module like the above to create a Javase project. Choose the appropriate template:
The following steps are the same as the steps for creating a java project. Pay attention to observe whether the settings such as settings are correct.
In addition, you can add the groupId and other information you set yourself.
Finally, we complete the directory of the complete web project:
Then we add the relevant dependencies to the pom file:
<!--加入servlet依赖(servlet的jar包)-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--jsp的相关依赖(jsp相关的jar添加进来)-->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
3.4 Import an existing maven project in Idea
3.4.1 Common Tips
3.4.2 Importing Existing Modules
-
Press and hold
Ctrl+Alt+Shift+S
to open the project structure settingsOr the folder icon with three small blue squares in the upper right corner of the interface, enter settings
-
Click the plus sign in the pop-up interface:
Add
, select Import Module to import the module -
Select the module to be imported and perform further JDK and other settings.
。