1.首先要在windows中安装tomcat和maven;如果没有可以去看我之前的博客


2.创建好maven项目之后,在pom.xml文件中加入这一行

idea 怎么运行maven项目 idea运行maven web项目_tomcat


3.鼠标右键项目打开"Open Module Settings"

idea 怎么运行maven项目 idea运行maven web项目_idea 怎么运行maven项目_02


4.点击Moudle下的web,双击飘红的地方

idea 怎么运行maven项目 idea运行maven web项目_web_03


5.复制其路径然后点击确定

idea 怎么运行maven项目 idea运行maven web项目_tomcat_04


6.点击"+"号,选择"web.xml"

idea 怎么运行maven项目 idea运行maven web项目_html_05


用刚才复制的地址替换"\WEB-INF\web.xml"以前的地址

idea 怎么运行maven项目 idea运行maven web项目_html_06


替换完之后,点击"ok"

idea 怎么运行maven项目 idea运行maven web项目_idea 怎么运行maven项目_07


出现如下界面

idea 怎么运行maven项目 idea运行maven web项目_maven_08


在Artifacts目录下有对应的war文件,最后点击"ok"即可

idea 怎么运行maven项目 idea运行maven web项目_tomcat_09


7.为了测试把login.html放在webapp文件夹下(login.html是自己写的,仅仅为了测试,没有什么其他的含义)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
</head>
<body>
    <h3>登录页面</h3>
    <form method="post" action="login">
        用户名:<input type="text" name="username" />
        <br><!-- br代表换行符 -->
        密码:<input type="password" name="password" />
        <input type="submit" value="登录" />
    </form>
</body>
</html>

idea 怎么运行maven项目 idea运行maven web项目_html_10


8.鼠标点击"maven",进入之后自己的Plugins可能飘红,表示插件没有下载到本次仓库,等待IDEA下载好就不会飘红了。如果自己不想下载,可以用我网盘上存的仓库

M2Repository提取码:s9x7

idea 怎么运行maven项目 idea运行maven web项目_idea 怎么运行maven项目_11


等不漂红了双击"package"

idea 怎么运行maven项目 idea运行maven web项目_maven_12


可以看到打包成功,并且新生成了target目录其下面有关于该项目的war包

idea 怎么运行maven项目 idea运行maven web项目_web_13


9.鼠标右击war包,找到war包位置

idea 怎么运行maven项目 idea运行maven web项目_web_14


复制war包

idea 怎么运行maven项目 idea运行maven web项目_maven_15


把这个war包复制到自己解压的tomcat根路径的webapps下

idea 怎么运行maven项目 idea运行maven web项目_idea 怎么运行maven项目_16


按 win + R键,输入cmd进入,然后输入startup启动Tomcat

idea 怎么运行maven项目 idea运行maven web项目_web_17


这时候tomcat根路径的webapps下会自动解压那个war包

idea 怎么运行maven项目 idea运行maven web项目_idea 怎么运行maven项目_18


10.双击自动解压的文件夹,即可看到login.html文件

idea 怎么运行maven项目 idea运行maven web项目_web_19


打开谷歌浏览器将login.html的路径写进去,访问出现登录页面即可说明成功

idea 怎么运行maven项目 idea运行maven web项目_idea 怎么运行maven项目_20