WAR不会部署到Tomcat 7.0.19。

5

我有一个WAR文件,Tomcat无法部署它。通常情况下,它会给出原因或某些指示,说明为什么无法部署该应用程序,但是Tomcat的catalina日志输出只显示:

SEVERE: Context [/appmon-qa] startup failed due to previous errors

这是 web.xml 文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <!-- The display name of this web application -->
    <display-name>AppMonitor</display-name>

    <listener>
        <listener-class>
            com.me.myorg.appmon.AppMonitor
        </listener-class>
    </listener>
</web-app>

还有 AppMonitor 类中的重要内容:

public class AppMonitor implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent event) {
        return;
    }

    @Override
    public void contextInitialized(ServletContextEvent event) {
        try {
            // Guts of my monitor app
        } catch(Exception exc) {
            System.out.println("Something bad happened!\n" + exc.getMessage());
        }
    }
}

而且日志输出非常模糊/没有描述:

INFO: Deploying web application archive appmon-qa.war
Jun 8, 2012 9:45:30 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jun 8, 2012 9:45:31 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/appmon-qa] startup failed due to previous errors
Jun 8, 2012 9:45:31 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
Jun 8, 2012 9:45:31 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Jun 8, 2012 9:45:32 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory host-manager
Jun 8, 2012 9:45:32 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory manager
Jun 8, 2012 9:45:32 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Jun 8, 2012 9:45:32 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jun 8, 2012 9:45:32 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 8, 2012 9:45:32 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8010"]
Jun 8, 2012 9:45:32 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2875 ms

我已经取消部署这个WAR包并且部署了另一个我知道能正常工作的,Tomcat 7.0.19也成功启动,因此我确定这不是Tomcat的配置问题。这显然是由于我的WAR包出了问题。目录结构如下:

appmon-qa.war/
    META-INF/
        MANIFEST.MF
    WEB-INF/
        classes/
            All of my binaries
        lib/
            All JAR dependencies
        web.xml

如果我的(超级简单的)web.xml出了问题,Tomcat应该会在日志输出中抱怨。如果我的web.xml / ServletContextListener没问题,但是在我的contextInitialized方法内部有些东西抛出了异常,那么catch块将会打印消息到控制台——但这并没有发生。
你有什么想法关于可能的潜在问题或者开始诊断的选项吗?谢谢!

这是公共的void contextDestroyed方法。这是一个打字错误吗? - Lai Xin Chu
真的是 public contextDestroyed(ServletContextEvent event) 吗?void 在哪里? - Petar Minchev
4
好的,我会尽力为您进行翻译。以下是需要翻译的内容:http://java.dzone.com/articles/tomcat-6-infamous-%E2%80%9CsevereTomcat 6 Infamous "SEVERE: Memory Leak" Error - What It Is and How to Fix ItIf you've worked with Tomcat 6 for any length of time, chances are good that you've run into the "SEVERE: Memory Leak" error message. This error can be frustrating to deal with, as it often doesn't provide much information about what's causing the problem.In this article, we'll take a look at what the "SEVERE: Memory Leak" error means, why it occurs in Tomcat 6, and some steps you can take to fix it.What is the "SEVERE: Memory Leak" error?The "SEVERE: Memory Leak" error message indicates that Tomcat has detected a memory leak in one of your web applications. A memory leak occurs when an application doesn't properly release memory after it's no longer needed, causing memory usage to steadily increase over time.Why does the "SEVERE: Memory Leak" error occur in Tomcat 6?There are a few different reasons why the "SEVERE: Memory Leak" error might occur in Tomcat 6:
  1. Improper configuration
  2. Incorrect use of certain APIs (such as the ThreadLocal class)
  3. Bugs in third-party libraries or frameworks
How can I fix the "SEVERE: Memory Leak" error?Here are a few steps you can take to fix the "SEVERE: Memory Leak" error:
  1. Analyze heap dumps to identify the cause of the leak
  2. Use tools like jmap or jvisualvm to monitor memory usage and identify potential leaks
  3. Make sure you're using the correct version of Tomcat for your application
  4. Check your web application for improper configuration or incorrect API usage
  5. Update any third-party libraries or frameworks that may be causing the issue
In conclusion, the "SEVERE: Memory Leak" error can be a frustrating problem to deal with in Tomcat 6, but with the right tools and techniques, it can usually be resolved. By analyzing heap dumps, monitoring memory usage, and making sure your application and dependencies are properly configured, you can keep your Tomcat environment running smoothly and avoid this pesky error message.
- Petar Minchev
2
http://mythinkpond.wordpress.com/2011/07/01/tomcat-6-infamous-severe-error-listenerstart-message-how-to-debug-this-error/ - Petar Minchev
1
展示你的web.xml文件。然后逐一注释掉那些具有启动加载的监听器和servlet。 - MJB
显示剩余6条评论
1个回答

1

在你的方法中,应该调用超类。

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
        super.contextInitialized(servletContextEvent);

...

以及

   @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        super.contextDestroyed(servletContextEvent);
    }

作为额外的措施,您可以确保在Tomcat服务器上增加日志级别(可能集成log4j)http://tomcat.apache.org/tomcat-7.0-doc/logging.html

Mihai


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接