Download, configure and create the first web project of maven--IDEA

One, Maven download

Maven is a project management tool that can build and depend on Java projects.

Maven download address: https://maven.apache.org/download.cgi
Insert picture description here

Two, Maven environment configuration

Maven is a Java-based tool, so the first thing to do is to install the JDK

Right-click "Computer", select "Properties", then click "Advanced System Settings", click "Environment Variables",
configure under the system variables: configuration path and bin

Variable name: MAVEN_HOME
Variable value: The path where the file is decompressed.

As shown in the figure below, the path is mine. You have to write your own path to
Insert picture description herefind the Path variable, click in, and create a new one: %MAVEN_HOME%\bin
Insert picture description here
and then confirm it all the way.

Check if the configuration is successful.
Enter: mvn -version in the DOS command box . If the following figure appears, you can see that the maven version and java version indicate that the configuration is successful.
Insert picture description here

3. Configuration file (settings.xml), modified to Alibaba Cloud Factory Library

The configuration file can be modified in two places.
One is that maven downloads from foreign warehouses by default, which will be slower, so it needs to be modified to domestic ones, such as Ali.
Second, where is the jar package after downloading it? The default is in the .m2 folder of the c drive user, which can be modified to any path

The configuration file is : settings.xml in the conf folder under the maven folder

Open the settings.xml configuration file, about line 55, and add the download location:

 <localRepository>要保存的路径</localRepository>

As shown in the figure below D:/Environment/MavenRepository, is the path I saved to
Insert picture description here
configure Alibaba Cloud Factory Library

The first step: about 160 lines, <mirrors> </mirrors>add in it:

    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>

As shown in the figure below
Insert picture description here
Step 2: Add in the pom.xml file of the project

<repositories>  
        <repository>  
            <id>alimaven</id>  
            <name>aliyun maven</name>  
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>false</enabled>  
            </snapshots>  
        </repository>  
</repositories>

Fourth, let idea use its own maven

Idea also has maven, and they all say it’s not easy to use, so use your own

1. In the lower right corner of the initial interface, there is Configure . After clicking, the first one is settings , click it
Insert picture description here
2. In the interface that appears, after selecting on the right, configure your maven path, as shown in the figure below, it is my maven path .

Note: Don't forget to click apply to make the configuration effective.

Insert picture description hereThen, when creating a maven project, this is the default, but of course you can also modify it.

Five, create a web project with maven

1. After clicking Create New Project , click Maven on the left, then check Create from archetype, select the web project, and then the next step. (You can also uncheck each step and import dependencies)

Insert picture description here
2. After clicking the next step, the following interface appears. Write a project name and package name.

Insert picture description here
3. The following interface appears. The red box is obviously the address of maven, the address of the configuration file used and the address of the jar package download . It is configured by us above (it is also possible to modify it now), if you don't modify it, you can click finish.

Insert picture description hereI need to wait a while for the first time because I have to download things.

4. The created directory is as shown below

Insert picture description here
5. Import tomcat

First click Add configuration on the upper right, as shown below

Insert picture description here

Then click + in the upper left corner and select Local under TomEE Server, as shown below.

Insert picture description here

There are three pictures below. The first picture is to select tomcat, the browser used to open the webpage, and the port number. Then click on the Deloyment on the right, configure as shown in Figure 2, and select the second one in Figure 3. After confirming, click Apply.

Insert picture description here

Insert picture description here
Insert picture description here

6. Run

After application and confirmation, you can see that the tomcat is imported and the run button can be clicked. As shown below

Insert picture description here
7. The operation is successful. As shown below

Insert picture description here

Six, missing java or resource

Careful students will find that the directory structure will be less, such as java or resource, we need to import it.

Right-click main, click New, and click Directory, as shown below.

Insert picture description here
The following picture will appear, and then click on the directory to be imported.
Insert picture description here
After selecting, you can find that you have everything you want in the project structure, as shown in the picture below.
Insert picture description here
Then you can write code happily

Guess you like

Origin blog.csdn.net/qq_42524288/article/details/107709679