9

经过数周的努力,我将其发布。我尝试并尝试,因为我对发布此内容感到内疚,因为有类似的线程。但我仍然得到略有不同的错误。所以我所拥有的是一个非常简单的spring(当然不需要是spring,bcz问题是maven)与maven的应用程序。

这是我的 pom.xml 中的插件部分。

<plugins>

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0</version>
            <configuration>
                <url>http://localhost:8080/manager</url>
                <username>tomcat</username>
                <password>s3cret</password>
                <path>/Test</path>
                <port>8080</port>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>

早些时候,我遇到了 maven tomcat 插件无法与 tomcat 7 等一起使用的问题,但现在有了“tomcat7-maven-plugin”,问题就解决了。我使用 ' http://localhost:8080/manager' 作为 URL。对于这个 maven tomcat 编译器插件的几乎所有线程都是关于构建失败的。但是我的构建成功了(我运行为 tomcat7:deploy)。问题是tomcat正在回复

tomcatManager 状态码:403,ReasonPhrase:Forbidden

以及我们在浏览器上遇到身份验证失败时看到的 html。相同的代码在我的 Linux 机器下运行良好。我尝试在 .m2 和 maven_home/conf 等内部的 settings.xml 中使用服务器元素的不同场景。仍然无法正常工作。

我发现 maven 无法对 tomcat 进行身份验证。找到用户名和密码,我可以使用 GUI 登录。所以在这里期待帮助。

ps - 我的 tomcat-users.xml 字段

<role rolename="manager-gui" />
<user username="tomcat" password="s3cret" roles="manager-gui"/>
4

5 回答 5

10

网址不正确尝试:

<url>http://localhost:8080/manager/text</url>

tomcat-users.xml 文件的内容是什么。您是否正确设置了权限?见http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

于 2013-02-20T09:54:45.073 回答
0

I could get tomcat deploy work but environment is different. So anyway I'm going to tell how I could do it since may be It'll help someone.

In this case I have tomcat6 as my web container and I'm using eclipse Helios as the IDE.

First of all I have haven environmental variables set as described in the maven web site(Maven download installation help). Which means environmental variables M2_HOME and M2 are set and M2 is in my path variable.

Then in eclipse I have maven installation folder, local repository(In case if it is not default) and settings.xml file correctly. (These setting are in Window -> Preferences -> Maven -> Installations and User settings)

In tomcat_home\conf\tomcat-users.xml I have created user with the role manager-script.(Note that here I use tomcat6)

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

In POM.xml I have maven tomcat plugin defined as follows.

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
    <url>http://localhost:8080/manager</url>
    <server>TomcatServer</server>
</configuration>
</plugin>

Then on eclipse Run Configurations I create a configuration to run goal "tomcat6:deploy" ( This site from apache says tomcat:deploy is the goal but it didn't work).

Which runs perfectly and deploy my app to the container. Once it is deployed app need to be undeplyed using "tomcat6:undeploy" before deploying again.

I'm not a expert about this and still I have doubts on some facts. But since I saw this question in lots of places I thought this will help someone it the same problem.

Thank you

于 2013-02-24T10:05:18.403 回答
0

在尝试了几件事之后,以下配置对我有用。请试一试

tomcat-users.xml

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

pom.xml

<!-- Maven Tomcat Plugin -->
<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <configuration>
      <url>http://localhost:8080/manager/html</url>
      <username>tomcat</username>
      <password>tomcat</password>
      <update>true</update>
      <path>/Test</path>
    </configuration>
</plugin>
于 2013-07-09T10:17:24.600 回答
0

今天我用 Tomcat 7 尝试了相同的应用程序。我需要将插件 artifactId 更改为“tomcat7-maven-plugin”。我必须将网址更改为“ http://localhost:8080/manager”。完成这些更改后,部署工作正常。我还发现 maven 在 .m2 文件夹中读取了 settings.xml 。mvaen_home/conf 中还有一个 settings.xml 文件,但它不是它读取的文件。我发现的另一件事是tomcat7没有取消部署,tomcat6有取消部署。

于 2013-02-25T17:52:24.173 回答
0

有时,当上述所有条件都匹配并且您仍然收到错误时,您可能正在使用 mvn tomat7:deploy 命令。同时,服务器由 Eclipse 维护,因此不会混为一谈。您可以在 Eclipse IDE 中停止服务器,然后使用 mvn 命令重试。

于 2013-04-12T17:22:10.163 回答