# Maven远程部署

第一步：修改 `{tomcat}/webapps/manager/META-INF/context.xml`文件

```
# 原来的内容
<Context antiResourceLocking="false" privileged="true" >
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
</Context>
# 修改为
<Context antiResourceLocking="false" privileged="true" >
    <!--
        <Valve className="org.apache.catalina.valves.RemoteAddrValve"
             allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
     -->   
</Context>
```

第二步：修&#x6539;*`{tomcat_home}/conf/tomcat-users.xml`*&#x6587;件，在节点`tomcat-users`中添加两个角色和一个用户（注意要修改用户名和密码，防止有人恶意进入）。

```
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="xiaoming" password="xiaoming_123456" roles="manager-script,manager-gui"/>
```

> 下面是tomcat文档中对于各个角色的权限说明：

```
- manager-gui — Access to the HTML interface.
- manager-status — Access to the "Server Status" page only.
- manager-script — Access to the tools-friendly plain text interface that is described in this document, and to the "Server Status" page.
- manager-jmx — Access to JMX proxy interface and to the "Server Status" page.
```

&#x20;第三步：在项目中的pom.xml文件的 build > plugins节点中添加远程部署插件：

```markup
<!--远程部署插件-->
<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <url>http://192.168.12.21:8080/manager/text</url>
        <username>xiaoming</username>
        <password>xiaoming_123456</password>
        <path>/${project.artifactId}</path>
    </configuration>
</plugin>
```

OK，现在可以部署了：

```
mvn tomcat7:redeploy -Ptest
```

## 参考

[Access Tomcat Manager App from different host](https://stackoverflow.com/questions/36703856/access-tomcat-manager-app-from-different-host)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maxwell.gitbook.io/way-to-architect/fu-wu-qi/tomcat/rang-tomcat-zhi-chi-maven-yuan-cheng-bu-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
