强制码头显示错误详细信息

Force jetty to display error details

我目前正在尝试学习如何使用 maven 和 jetty。但是我有一个问题,我的球衣页面抛出错误 500,它自己的错误不是我的问题。 但我希望码头为我显示完整的错误消息,而不是

HTTP ERROR 500

Problem accessing /hello. Reason:

    Internal Server Error

遇到这样的错误,如何让jetty显示完整的错误详情? 这是我的 pom 文件

<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/maven-v4_0_0.xsd">

    <properties>
        <docker.imageName>${artifactId}</docker.imageName>
        <spring.version>4.1.5.RELEASE</spring.version>
        <jersey.version>2.5</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mysite</groupId>
    <artifactId>mycode</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>mycode</name>

    <build>
        <finalName>${artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.2.v20140723</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <!-- <jettyConfig>jetty.xml</jettyConfig> -->
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>bash-maven-plugin</artifactId>
                <version>1.0-ts-20141204</version>
                <executions>
                    <execution>
                        <id>package</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <script>
                                rsync -a --delete ${project.basedir}/docker/ ${project.build.directory}/docker
                                cp -p ${project.build.directory}/${project.build.finalName}.war ${project.build.directory}/docker/root.war
                                find ${project.build.directory}/docker | xargs touch -t 197409101630.00
                                docker build -f DockerfileBase -t mysite/jettybase ${project.build.directory}/docker
                                docker build -t mysite/${docker.imageName} ${project.build.directory}/docker
                            </script>
                        </configuration>
                    </execution>
                    <execution>
                        <id>deploy</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>deploy</phase>
                        <configuration>
                            <script>
                                <!--docker push ${docker.imageName}-->
                                echo '123'
                            </script>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Jersey -->
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
            <version>${jersey.version}</version>
        </dependency>


        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
            <artifactId>jersey-container-servlet</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <!-- Jersey + Spring -->
        <dependency>
            <groupId>org.glassfish.jersey.ext</groupId>
            <artifactId>jersey-spring3</artifactId>
            <version>${jersey.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Spring dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>
</project>

如果您的任何 servlet 或过滤器执行 response.sendError(500),这就是您将得到的结果。没有堆栈跟踪。

如果您在服务器上没有定义 ErrorHandler,您也会得到。

如果您有 ErrorHandler,那么要么它调用了 .setShowStacks(false),要么就是没有要显示的堆栈跟踪。

如果输出显示 Powered by Jetty://,那么它是由 Jetty 中的某些东西产生的,如果不是,那么它不是产生该错误页面的 Jetty 组件。

最后,您还可以在 WEB-INF/web.xml 中为您的 webapp 设置自己的错误处理,使用文档获取帮助(例如使用什么属性来从请求中为您获取适当的堆栈跟踪对象)

https://www.eclipse.org/jetty/documentation/current/custom-error-pages.html