社区版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(可选配置) 用于登录http://10.1.0.149: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>http://localhost: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   http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html

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 the finalName by 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 ,并运行当前项目

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值