Maven 2 Tomcat maven插件401错误
我正在学习tomcat的基础知识,当我试图在tomcat上部署我的web应用程序时,我遇到了以下错误Maven 2 Tomcat maven插件401错误,maven-2,maven,maven-plugin,maven-3,Maven 2,Maven,Maven Plugin,Maven 3,我正在学习tomcat的基础知识,当我试图在tomcat上部署我的web应用程序时,我遇到了以下错误 [ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project struts2-demoapp: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project struts2-demoapp: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/html/deploy?path=%2FmkyWebApp&war= -> [Help 1]
[ERROR]
照此看来,war文件位置似乎没有被传递给tomcat管理器
tomcat-users>
<user name="admin" password="admin" roles="admin,manager" /><!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them.
-->
<role rolename="manager"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
<url>http://localhost:8080/manager/html</url>
<server>myserver</server>
<path>/mkyWebApp</path>
</configuration>
</plugin>
</plugins>
</build>
在my setting.xml中有以下条目
<server>
<id>Tomcat6.x</id>
<username>admin</username>
<password>admin</password>
</server>
Tomcat6.x
管理
管理
我不确定这里到底出了什么问题。这方面的任何帮助都会有所帮助。您需要将settings.xml中的凭据映射到pom.xml中的服务器配置 在您的例子中,这样做只是设置服务器的
元素,以匹配pom.xml中服务器的主机名
由于您指向的是localhost
,因此id也必须是localhost
。
更改主机名时,还必须更新settings.xml。它位于:Maven设置中的服务器/id
标记必须与POM文件中的配置/server
值匹配,即将Tomcat6.x
放入POM文件中
POM文件中的tomcat maven插件
条目还有一些其他小问题:
1.1
标记/html
后缀是不必要的(参见
标记的默认值)<server>
<id>Tomcat6.x</id>
<username>admin</username>
<password>admin</password>
</server>
Tomcat6.x
管理
管理
到
我的服务器
管理
管理
如果您使用的是Tomcat7,请使用
<url>http://localhost:8080/manager/html</url>
http://localhost:8080/manager/html
如果tomcat 6
<url>http://localhost:8080/manager</url>
http://localhost:8080/manager
启动tomcat运行tomcat7:deploy或tomcat6:deploy当我遇到这个问题时。我的问题是使用旧版本
<groupId>org.codehaus.mojo</groupId>
org.codehaus.mojo
而不是使用
<groupId>org.apache.tomcat.maven</groupId>
org.apache.tomcat.maven
我的设置如下
~/.m2/settings.xml
<settings>
<servers>
<server>
<id>localhost</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
</settings>
<tomcat-users>
<role rolename="manager"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui,manager-script,tomcat,manager"/>
</tomcat-users>
本地服务器
雄猫
雄猫
pom.xml
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager</url>
<server>localhost</server>
<path>/myapppath</path>
</configuration>
</plugin>
org.apache.tomcat.maven
tomcat6 maven插件
http://localhost:8080/manager
本地服务器
/myapppath
tomcat/conf/tomcat users.xml
<settings>
<servers>
<server>
<id>localhost</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
</settings>
<tomcat-users>
<role rolename="manager"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui,manager-script,tomcat,manager"/>
</tomcat-users>
我建议您使用此插件:
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.1.2</version>
org.codehaus.cargo
cargo-maven2-plugin
1.1.2
这对Tomcat7很有帮助。我对mojoorg.codehaus.mojo
但是现在,使用Cargo插件,部署运行起来非常顺利。尝试在settings.xml的“id”字段中添加“localhost”而不是“Tomcat6.x”。@Tarlog:使用localhost的概念是什么?因为使用这个值解决了这个问题,所以我想我会添加一个明确的答案:)感谢Tarlog的描述:)