我在将 tomcat 作为服务部署到远程机器时遇到了问题。 我的 tomcat-users 如下:
<tomcat-users>
<role rolename="manager"/>
<user username="admin" password="admin" roles="tomcat, admin, manager-gui, manager-script"/>
</tomcat-users>
我的 settings.xml 是:
<settings>
<pluginGroups>
<pluginGroup>org.apache.tomcat.maven</pluginGroup>
</pluginGroups>
<servers>
<server>
<id>tomcat7</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
</settings>
我的 pom.xml 具有以下内容:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<server>tomcat7</server>
<url>http://localhost:8081/manager/text</url>
<warFile>target/editor-${project.version}.war</warFile>
</configuration>
而且我不断在 maven 控制台的输出中收到 401 Unauthorized。你能告诉我我做错了什么吗?
最佳答案
以下方法对我有用。
请更改您的
pom.xml
以包含<project> ... <build> <plugins> .... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>my-tomcat</server> <path>/myapp</path> </configuration> </plugin> </plugins> ... </build> ... </project>
确保您的 Tomcat 7 服务器在
TOMCAT_HOME/conf/tomcat-users.xml
上具有以下行:<!-- Role to manage WAR files via HTML /manager. The name should be as is! --> <role rolename="manager-gui"/> <!-- Role to manage WAR files via script like Maven. The name should be as is! --> <role rolename="manager-script"/> <!-- One user cannot have manager-gui and manager-script roles --> <user username="managerGui" password="managerPwd" roles="manager-gui"/> <user username="manager" password="managerPwd" roles="manager-script"/>
配置您的
USER_HOME/.m2/settings.xml
以包含密码。<settings> ... <servers> ... <server> <id>my-tomcat</id> <username>manager</username> <password>managerPwd</password> </server> </servers> </settings>
使用
部署mvn tomcat7:redeploy
阅读更多关于 http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html 的信息
关于tomcat7 maven 插件部署失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13249354/