我的/users//settings.xml 中有以下配置。
在插件组下:
<pluginGroup>org.apache.tomcat.maven</pluginGroup>
在服务器下:
<server>
<id>localhost</id>
<username>tom</username>
<password>cat</password>
</server>
在配置文件下:
<plugin>
<configuration>
<server>localhost</server>
<url>http://localhost:8080/manager/text</url>
<path>/</path>
</configuration>
</plugin>
我运行带有 -X 选项的 maven 命令,我看到以下内容:
[DEBUG] Reading global settings from C:\Tools\apache-maven-3.1.1\bin\..\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\<user>\.m2\settings.xml
我在 tomcat 用户 xml 文件中有 manager-script
角色。
当我通过浏览器手动验证访问时,它工作正常。但是当我运行 mvn tomcat7:deploy
时,我得到以下信息:
Receiving response: HTTP/1.1 401 Unauthorized
用户名和密码正确。我手动验证了它。还有什么可能是错的? 谷歌搜索没有多大帮助。
编辑:日志中的更多详细信息。
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Cache-Control: private
Expires: Wed, 31 Dec 1969 18:00:00 CST
WWW-Authenticate: Basic realm="Tomcat Manager Application"
Set-Cookie: JSESSIONID=7320C7326C51E8F7FF9F4D23A39E6971; Path=/manager/; HttpOnly
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Thu, 24 Apr 2014 02:56:27 GMT
Cookie accepted: "[version: 0][name: JSESSIONID][value: 7320C7326C51E8F7FF9F4D23A39E6971]
[domain: localhost][path: /manager/][expiry: null]".
Connection can be kept alive indefinitely
Authentication required
localhost:8080 requested authentication
Authorization challenge processed
Authentication failed
Clearing cached auth scheme for http://localhost:8080
编辑: 好吧,这就是我发现的。当我从 mvn 命令传递用户名和密码时,它工作正常。但它不是从 settings.xml 中提取的。
它会响铃吗?我也尝试将配置内容移至 MAVEN_HOME/config/settings.xml。 (删除了用户settings.xml)。但还是一样。
任何设置缓存?
编辑:
我使用 -X 打开了调试器。即使我删除了/user/.m2/settings.xml,它仍然说正在读取该文件。
[DEBUG] Reading global settings from C:\Tools\apache-maven-3.1.1\bin\..\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\<user>\.m2\settings.xml
如何冲洗?
最佳答案
插件配置应该是这样的:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<server>text</server>
<url>http://localhost:8080/manager/text</url>
</configuration>
</plugin>
这应该有效
我猜测您要部署的应用程序名为 text。如果不是,请将文本替换为您的 Web 应用程序名称。
我也会尝试删除最后一个 <path>/</path>
元素看看这是否有帮助...
关于java - Tomcat/Maven 插件 - 未经授权的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23272360/