【问题标题】:Tomcat / Maven plugin - Unauthorized errorTomcat / Maven 插件 - 未经授权的错误
【发布时间】:2014-04-24 14:49:17
【问题描述】:

我的 /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

如何冲洗?

【问题讨论】:

  • 您确定用户名/密码不应该是tomcat/tomcat?这是典型的设置:&lt;user name="tomcat" password="tomcat" roles="admin-gui,manager-gui" /&gt;。三重检查您的 tomcat-users.xml。添加用户后是否重启过Tomcat?
  • 它并没有说登录名/密码不正确。它说您无权访问您请求的资源
  • @jedison 是的,我确实检查了几次。我改变了u / p。所以是的,我上面发布的那个是正确的。
  • @hoaz 还有什么要调查的吗?
  • 你访问什么网址?

标签: java maven tomcat deployment unauthorized


【解决方案1】:

插件配置应该是这样的:

<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 应用程序名称替换文本。 另外我会尝试删除最后一个 &lt;path&gt;/&lt;/path&gt; 元素,看看这是否有帮助......

【讨论】:

  • /text 是一个 tomcat URL,如 /manager。并且不需要上述插件配置。因为它在 配置下指定。
  • 是的,我看到你需要为 tomcat 7 添加它。我想我也需要更新我的项目:P
  • 另一个想法是检查两个 maven settings.xml 中是否有 路径。他们可能无法一起工作
  • 我查过了。并且它没有重复
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 1970-01-01
  • 2017-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多