IDEA builds Maven and uses Maven to package and deploy

1. Configure Maven's environment variables

a. First, we go to the maven official website to download the Maven program and unzip it to the installation directory, as shown in the figure:

 

b. Configure the environment variable of M2_HOME, and then add the variable to Path
 Note: The M2_HOME environment variable of JAVA_HOME must be present, otherwise Maven will prompt an error. Configure environment variables as shown:

 

c. If you want to modify Maven's local warehouse location, you can directly find the setting configuration file under the conf file in the Maven installation directory, and set localRepository to the local warehouse location
<localRepository>E:\java\repo</localRepository>
d. Re-open the command prompt cmd (administrator), enter mvn --version, as shown in the figure, the installation is successful
2. Build Maven in the Idea development environment
 a. After configuring Maven, we need to configure Maven for Idea, then we must first install Idea. After the installation is complete, open Idea to set Maven, as shown in the figure:
b. After clicking Setting, set the Maven home directory and user settings file and local repository under the Maven node as shown in the figure: (repo is the maven warehouse)

 

At this point, our entire Idea configuration Maven is complete
3. Use Maven to develop JavaWeb projects (Idea14)
a. Through the above steps, you have installed Maven and developed a Maven JavaWeb project, then you need to publish the JavaWeb package (war file) to Tomcat. How to package it?
b. You can see a Maven Projects in the rightmost navigation bar in Idea, click to open, as shown in the figure:

 

c. Next we can use this simple tool to package Maven (war).
d. As shown in Figure 2, when you click Run Maven Build, an error occurs, as shown in the figure:
e. After the above error occurs, follow the steps below to solve it, click File->Setting->Enter Maven in the search box and enter Maven to directly navigate to the Maven node->Runner, open this content (-Dmaven.multiModuleProjectDirectory= $M2_HOME) into the VM Options text box and click OK.
f. As shown in Figure 2, we run it again and find that no error is reported, and some content is entered, which proves that the program can be packaged.
g. Select install, right-click and select Run. After the operation is complete, you will be prompted where the packaged war package is, as shown in the figure 

 

h. Then find the war package, copy it to the WebApps folder of Tomcat, and then directly visit the website to access

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324501537&siteId=291194637