Article preview:
(First time using maven, you need to connect to the Internet)
1. IDEA configures local maven
使用idea创建maven工程之前需要将本地的maven配置到idea环境中,配置方法如下:
1.1 Configure local maven
- Step 1: Open default settings (effective for future new projects):
2. Step 2: Configure the paths of maven_home and settings.xml:
1.2 Configure maven parameters
使用idea创建maven项目后,默认会去网络中下载一些配置资源。需要设置参数archetypeCatalog。
设置方法如下:将-DarchetypeCatalog=internal 设置到Maven--Runner--VM Options中。
参数:-DarchetypeCatalog=internal
2. Create a maven java project
使用maven创建的项目可分为3种类型:普通java项目,web项目和maven的父工程。
这三种项目对象的打包方式分别是:jar,war和pom。
2.1 Creation steps
Step 1: File–New–Project
Step 2: Select maven and then next step:
Step 3: Fill in the coordinate information of the project:
Step 4: Specify the project name and path: idea will remove the - in the project name, we Just add it.
2.2 Introduction to java project directory
2.3 Testing
Write main program code
Write test code
Test results
3. Create a web project
3.1 Creation steps
Step 1: Create a normal java project.
Follow the steps to create a maven java project.
Step 2: Configure the packaging method.
The packaging method of the web project is war, and open the pom file of the maven project. Add a label under the coordinate information of the project and set the packaging method.
Step 3: Configure the webapp directory and web.xml
Open the Project Structure view
The effect is as follows
Step 4: Creation is completed
设置完成之后,main目录下会创建webapp-WEB-INF-web.xml。
3.2 Publish web projects
Step 1: Edit Configurations
Step 2: Add local tomcat.
Follow the sequence of numbers and icons in the figure below: + --> Tomcat Server --> Local
Step 3: Configure tomcat
Step 4: Start testing
在webapp目录下新建一个index.html文件,文件内容如下:
After starting tomcat, visit index.html. If index.html can be accessed correctly. Description project creation OK.