Maven 热部署

部署前提:须要启动一个tomcat服务器。服务器url为http://127.0.0.1:8080。(能够是远程服务器 url)html

修改tomcat配置:conf/tomcat-users.xmlapache

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

pom文件。 服务器

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <configuration>
                <uriEncoding>UTF-8</uriEncoding>
                <!--<port>8080</port>-->
                <path>/</path>
                <url>http://127.0.0.1:8080/manager/text</url>
                <username>tomcat</username>
                <password>tomcat</password>
            </configuration>
        </plugin>
    </plugins>
</build>

配置命令行参数socket

附相关错误解决办法maven

0. 不要使用 Java 开发工具中的自带的tomcat启动方式,可能发生socket异常。工具

1.Connection refused错误开发工具

报错信息以下:ui

[ERROR]Failed to execute goal org.apache.tomcat.maven: tomcat7-maven-plugin: 2.0- SNAPSHOT: deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]url

缘由:未启动Tomcat服务器

解决办法:先启动Tomcat服务器再选择Run

2. 401错误

报错信息以下:

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/text/deploy?path=%2Fhelloworld -> [Help 1]

缘由:权限问题

解决办法在$CATALINA_BASE/conf/tomcat-users.xml,

如D:\apache-tomcat-7.0.34\conf\tomcat-users.xml文件中添加权限

<role rolename=”manager”/>

<user username=”admin” password=”admin” roles=”manager”/>

修改pom.xml文件,在<configuration>  </configuration>中添加

<username>admin</username>  <password>admin</password>

3.403错误

报错信息以下:

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/html/deploy?path=%2Fhelloworld -> [Help 1]

缘由:产生该问题有可能由于两个缘由,具体参看法决办法

解决办法:

1)若是使用的是Tomcat 7,须要修改pom.xml中部署的url地址,将<url>http://localhost:8080/manager</url>改<url>http://localhost:8080/manager/text</url>

2)给tomcat用户权限分配上,须要同时具有manager-gui和manager-script权限,我在遇到该问题时,就是忘了分配manager-script权限。

正确的conf/tomcat-users.xml配置应为:

<tomcat-users>

<role rolename="manager-gui"/>

<role rolename="manager-script"/>

<user username="admin” password="admin" roles="manager-gui, manager-script"/>

</tomcat-users>

相关文章
相关标签/搜索