强制jetty显示错误详细信息

时间:2015-03-26 10:56:50

标签: maven jetty maven-jetty-plugin

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

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>

1 个答案:

答案 0 :(得分:2)

如果您的任何servlet或过滤器执行了response.sendError(500),那就是您将获得的内容。没有堆栈跟踪。

如果您在定义的服务器上没有ErrorHandler,那也是您将获得的。

如果你有一个ErrorHandler,那么它调用了.setShowStacks(false),或者根本没有要显示的堆栈跟踪。

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

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

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