无法调用 Tomcat 管理器:服务器返回 HTTP 响应代码:401

发布于 2024-12-05 14:04:53 字数 6640 浏览 1 评论 0原文

我正在尝试从 maven 将 war 部署到远程 tomcat 服务器,但在 NetBeans 中出现以下错误:

Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli)
on project noca: Cannot invoke Tomcat manager:
Server returned HTTP response code: 401 for URL:
http://12.34.56.78/manager/html/deploy?path=%2Fnoca&war= -> [Help 1]

我发现很奇怪 war 没有值,我不知道为什么。

当我浏览此 URL 时,我在 Tomcat 管理器中看到以下内容:

FAIL - Invalid context path null was specified

这是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>net.test</groupId>
    <artifactId>noca</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <server>Plasma01</server>
                    <url>http://12.34.56.78/manager/html</url>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

服务器在我的 maven setting.xml 中正确定义。

我做错了什么?

PS:我见过类似的问题,但它没有回答我的问题。

解决方案

作为记录,我按照 Alexey 的建议修改了我的 pom.xml ,并且它有效:

    <!-- plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
            <server>Plasma01</server>
            <url>http://12.34.56.78/manager/html</url>
        </configuration>
    </plugin -->

    <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <configuration>
            <container>
                <containerId>tomcat6x</containerId>
                <type>remote</type>
            </container>
        <configuration>
        <type>runtime</type>
        <properties>
            <cargo.tomcat.manager.url>
                http://12.34.56.78/manager
            </cargo.tomcat.manager.url>
            <cargo.remote.username>xxxx</cargo.remote.username>
            <cargo.remote.password>yyyy</cargo.remote.password>
        </properties>
        </configuration>
            <deployer>
                <type>remote</type>
                <deployables>
                    <deployable>
                        <groupId>net.test</groupId>
                        <artifactId>noca</artifactId>
                        <type>war</type>
                    </deployable>
                </deployables>
            </deployer>
        </configuration>
    </plugin>

I am trying to deploy a war to a remote tomcat server from maven, but I get the following error in NetBeans:

Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli)
on project noca: Cannot invoke Tomcat manager:
Server returned HTTP response code: 401 for URL:
http://12.34.56.78/manager/html/deploy?path=%2Fnoca&war= -> [Help 1]

I find it strange that there is no value for war and I don't know why.

When I browse this URL, I get the following in Tomcat's manager:

FAIL - Invalid context path null was specified

Here is my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>net.test</groupId>
    <artifactId>noca</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <server>Plasma01</server>
                    <url>http://12.34.56.78/manager/html</url>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

The server is properly defined in my maven setting.xml.

What am I doing wrong?

P.S.: I have seen this similar question, but it does not answer the issue I have.

SOLUTION

For the record, I modified my pom.xml as following following Alexey's suggestion and it works:

    <!-- plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
            <server>Plasma01</server>
            <url>http://12.34.56.78/manager/html</url>
        </configuration>
    </plugin -->

    <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <configuration>
            <container>
                <containerId>tomcat6x</containerId>
                <type>remote</type>
            </container>
        <configuration>
        <type>runtime</type>
        <properties>
            <cargo.tomcat.manager.url>
                http://12.34.56.78/manager
            </cargo.tomcat.manager.url>
            <cargo.remote.username>xxxx</cargo.remote.username>
            <cargo.remote.password>yyyy</cargo.remote.password>
        </properties>
        </configuration>
            <deployer>
                <type>remote</type>
                <deployables>
                    <deployable>
                        <groupId>net.test</groupId>
                        <artifactId>noca</artifactId>
                        <type>war</type>
                    </deployable>
                </deployables>
            </deployer>
        </configuration>
    </plugin>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫离伤花 2024-12-12 14:04:53

尝试使用 cargo 来控制 tomcat 和部署,简单又有效。

Try to user cargo to control tomcat and deployment, it's easy and worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文