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
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
find the Path variable, click in, and create a new one: %MAVEN_HOME%\bin
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.
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
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
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
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.
Then, 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)
2. After clicking the next step, the following interface appears. Write a project name and package name.
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.
I need to wait a while for the first time because I have to download things.
4. The created directory is as shown below
5. Import tomcat
First click Add configuration on the upper right, as shown below
Then click + in the upper left corner and select Local under TomEE Server, as shown below.
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.
6. Run
After application and confirmation, you can see that the tomcat is imported and the run button can be clicked. As shown below
7. The operation is successful. As shown below
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.
The following picture will appear, and then click on the directory to be imported.
After selecting, you can find that you have everything you want in the project structure, as shown in the picture below.
Then you can write code happily