社区版idea 基于maven配置tomcat

idea分社区版和收费版,收费版默认集成了tomcat插件,而社区版主要提供了android开发工具,没有集成tomcat。

为此我也搜索了好久,发现可以通过maven-tomcat-plugin插件实现

配置环境: ubuntu14.04

jdk1.8

社区版ideaIC-14.03

maven3.1.1 (这里注意,我用jdk1.8加最新的maven3.3.1,下载jar包时会出错,所以用了3.1.1)

tomcat 8.0

1.idea安装maven-tomcat-plugin插件

2.配置tomcat管理用户

1) 打开tomcat安装目录下的配置文件 conf/tomcat-users.xml

2)配置用户

<role rolename="manager-gui"/><role rolename="manager-script"/><user username="自定义的用户名1" password="密码" roles="manager-gui"/><user username="自定义的用户名2" password="密码" roles="manager-script"/>

配置完需要重启

其中用户1(可选配置) 用于登录:8080/manager/html ,,该页面为tomcat的网页管理界面,可以查看和管理目前tomcat上部署的网站

用户2用于maven插件用脚本部署网站

3.修改网站下的pom.xml文件

<build> <finalName>riskWeb</finalName> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>:8080/manager/text</url> <server>wsWeb</server> <path>/riskWeb</path> </configuration> </plugin>

</build>

其中红色部分是自定义部分,finalName和path是网站部署目录,这两种可以选一种,参考下面附1

server是自定义的部署用户id,必须与下面4中的配置统一

4.在maven中配置部署服务器的用户信息

在maven安装目录conf/setting.xml 或者~/.m2/setting.xml中配置如下信息(一定要在安装maven时,自带的setting.xml中)

在servers下添加

<server> <id>3中pom文件中的wsWeb</id> <username>tomcat中配置的script用户,即上述用户2</username> <password>密码</password> </server>

5.执行mvn tomcat:deploy部署网站

附1

Using a different context path

The default context path is/${project.build.finalName}, which itself defaults to/${artifactId}-${version}.

The preferred way of changing the context path is to change thefinalNameby adding the following to your pom.xml:

<build><finalName>mycontext</finalName></build>

Alternatively, a different context path can be specified by adding an explicit plugin configuration block to your pom.xml as follows:

<plugin><groupId>org.codehaus.mojo</groupId><artifactId>tomcat-maven-plugin</artifactId><configuration><path>/mycontext</path></configuration></plugin>

附2

下面介绍几个常用的Goal

命令描述

tomcat:deploy部署一个web war包

tomcat:reload重新加载web war包

tomcat:start

启动tomcat

tomcat:stop

停止tomcat

tomcat:undeploy

停止一个war包

tomcat:run启动嵌入式tomcat ,并运行当前项目

没有什么可凭仗,只有他的好身体,没有地方可去,只想到处流浪。

社区版idea 基于maven配置tomcat

相关文章:

你感兴趣的文章:

标签云: