用过idea开发的码农都知道,idea中内置了许多服务启动插件,其中用的最多的就是我们开发时直接使用jetty启动,在测试环境部署时一般用tomcat,所以为保持发布时不受环境影响,本机也配tomcat,但实际上即使用同版本号的tomcat,windows下和linux下也会偶有不同,这里不去研究它是web服务器问题还是操作系统问题,我们来看一下idea maven项目中如何配置服务启动。
首先,看一下pom.xml配置

点击run启动

大家可以看到configuration节点的部分,我们配置可以随时修改启动端口,如果不配置它,那我们就需要到run->edit configurations->Defaults->Tomcat Server->Local去修改默认端口。

这只是通过idea内置server启动,那么我想要部署到指定版本的tomcat下该如何呢?
我们在Local的server中指向某版本tomcat

并在tomcat-users.xml文件中增加
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="manager-script"/>
在.m2下的settings.xml中配置
<server>
<id>tomcat</id>
<username>admin</username>
<password>admin</password>
</server>
然后把之前pom中tomcat配置注释的部分打开,先启动tomcat,然后点击idea右侧maven插件的tomcat7:deploy,就将应用打包war包后传到tomcat的webapps下了,不过这里好像需要配置上下文名称,不如用内置并配置80用的爽。
网友评论