Tomcat配置

  1. conf/tomcat-users.xml

    1
    2
    3
    4
    <role rolename="admin-gui"/>
    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <user username="admin" password="admin123456" roles="manager-gui,admin-gui,manager-script"/>
  2. manager/META-INF/context.xml

    注释掉下面内容,允许远程访问

    1
    2
    3
    4
    5
    6
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

    或者改为
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    allow="^.*$" />
  3. 默认支持上传war 文件最大大小为 50MB,修改为 500MB

    webapps/manager/WEB-INF/web.xml

    1
    2
    3
    4
    5
    6
    <multipart-config>
    <!-- 500MB max -->
    <max-file-size>524288000</max-file-size>
    <max-request-size>524288000</max-request-size>
    <file-size-threshold>0</file-size-threshold>
    </multipart-config>

注意:配置后启动Tomcat,远程部署才能执行

Maven 配置「可以跳过」

conf/setting.xml 文件 servers 中添加

1
2
3
4
5
 <server>
<id>Tomcat9</id>
<username>admin</username>
<password>admin123456</password>
</server>

项目 pom.xml

build-plugins 中添加插件tomcat7-maven-plugin

注意:

  1. server 与上面 id一致,username 和 password 对应上面配置,都要与 Tomcat conf/tomcat-users.xml中配置一致
  2. path 为发布到 webapps 中的项目目录名称。为 / 时,路径为 ROOT;为 /scm 时,路径为 scm
1
2
3
4
5
6
7
8
9
10
11
12
13
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://192.168.0.109:8080/manager/text</url>
<server>Tomcat9</server>
<username>admin</username>
<password>admin123456</password>
<update>true</update>
<path>/scm</path>
</configuration>
</plugin>

部署

1
2
3
mvn clean install   //第一次必须要 install

mvn tomcat7:deploy //该命令会检测是否存在 war文件,不存在会先编译打包「target目录」,再上传到目标服务器目录