如何使用catalina.jar

时间:2013-05-05 12:51:29

标签: java tomcat

我正在使用tomcat 7.0.39的websocket函数,所以我必须在我的类路径中包含catalina.jar。但是当我部署我的项目时,如果我将jar文件部署到WEB-INF / lib中,我会得到以下异常:

java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addServlet

并且当没有部署catalina.jar时,我得到ClassNotFoundException:

java.lang.ClassNotFoundException: org.apache.catalina.websocket.MessageInbound

有人请帮帮我。

堆栈跟踪:

java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addServlet
    at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:802)
    at org.apache.tomcat.util.digester.SetNextRule.end(SetNextRule.java:201)
    at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1057)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:604)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1759)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2915)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1543)
    at org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1694)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1197)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:882)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:317)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5081)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:620)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:303)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:431)

2 个答案:

答案 0 :(得分:1)

7.0.x中的Web套接字支持是经验性的(很快将被弃用,并替换为Tomcat 8中JSR 356实现的端口)。

这样的副作用是API可以并且确实在点发布之间发生变化。因此,您必须从要部署的Tomcat版本中再次编译Tomcat JAR中的代码。您看到的错误表明版本不匹配。

无需在Web应用程序中打包任何Tomcat JAR。

答案 1 :(得分:0)

你真的需要把catalina.jar放在你的类路径中吗? Catalina.jar应该已经存在于tomcat / lib目录中。 Tomcat类加载器将从其自己的lib目录加载jar,因此它是父类加载器,因此不会选择类路径或应用程序catalina.jar。希望您能够通过这些信息解决您的问题。

您收到NoSuchMethodDefinition错误,这意味着您用于编译的jar具有该方法,但加载执行的jar没有该方法定义。检查更换tomcat / lib中的catalina.jar与用于编译代码的jar。