1

我在新工作中继承了几个 Java 项目,但我在设置方面遇到了一些问题。我正面临一个研究如此普遍的问题。“java.lang.NoClassDefFoundError: org/hibernate/Session”,把所有的jars甚至不必要的hibernate都映射到了classpath中。

我正在使用 tomcat 7、hirbernat 4、jre7。

每个项目都扩展了在 lib 文件夹中包含所有必要 jar 的 compnet。

我需要把那些已经映射的罐子放在这个项目中吗?

错误在这里被捕获:

    @Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    HibernateUtil.currentSession();
}

类路径:

<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/xstream 1.3/xpp3_min-1.1.4c.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/xstream 1.3/xstream-1.3.1.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"/>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/commons fileupload 1.2.1/commons-fileupload-1.2.1.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/antlr.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/commons-collections.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/dom4j.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/ejb3-persistence.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/hibernate-annotations.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/hibernate-commons-annotations.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/hibernate-validator.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/hibernate3.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/javassist.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/jta.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/jtds-1.2.4.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/log4j.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/slf4j-api.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/hibernate 3/slf4j-log4j12.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/commons logging/commons-logging-1.1.1.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/commons logging/commons-logging-adapters-1.1.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/commons logging/commons-logging-api-1.1.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/pkg_ocorrencia"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/pkg_mandado"/>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/commons-beanutils-1.8.2.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/commons-digester-1.7.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/groovy-all-1.5.5.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/iText-2.1.0.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/jasperreports-3.7.4.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/jasperreports-chart-themes-3.7.4.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/jasperreports-extensions-3.5.3.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/jasperreports-fonts-3.7.4.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/spring.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/xalan.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/jfreechart-1.0.12.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/jasper - ireport 3.7.4/jcommon-1.0.15.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/Compnet"/>
<classpathentry exported="true" kind="lib" path="/Compnet/lib/commons email 1.2/commons-email-1.2.jar"/>
<classpathentry kind="lib" path="D:/Tomcat 7/apache-tomcat-7.0.27/lib/servlet-api.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/antlr-2.7.7.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/c3p0-0.9.1.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/ehcache-core-2.4.3.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-c3p0-4.1.4.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-commons-annotations-4.0.1.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-core-4.1.4.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-ehcache-4.1.4.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-entitymanager-4.1.4.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-envers-4.1.4.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-infinispan-4.1.4.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/hibernate-proxool-4.1.4.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/infinispan-core-5.1.4.FINAL.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/javassist-3.15.0-GA.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/jboss-logging-3.1.0.GA.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/jboss-marshalling-1.3.11.GA.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/jboss-marshalling-river-1.3.11.GA.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/jboss-transaction-api_1.1_spec-1.0.0.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/jgroups-3.0.9.Final.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/proxool-0.8.3.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/rhq-pluginAnnotations-3.0.4.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/slf4j-api-1.6.1.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/stax2-api-3.1.1.jar"/>
<classpathentry kind="lib" path="/Compnet/lib/hibernate4/woodstox-core-asl-4.1.1.jar"/>

<classpathentry kind="output" path="build/classes"/>

堆栈式:

java.lang.NoClassDefFoundError: org/hibernate/Session at br.com.flex4j.servlet.genericActionServlet.init(genericActionServlet.java:29) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129) 在 org.apache.catalina.core.StandardContextValve.invoke( StandardContextValve.java:175) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 在 org.apache.catalina .core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263) 在 org.apache.coyote。http11.Http11Processor.process(Http11Processor.java:844) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) 在 org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JioEndpoint.java:447) at java.lang.Thread.run(Unknown Source) 引起:java.lang.ClassNotFoundException: org.hibernate.Session at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358 ) 在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) ... 13 更多ClassNotFoundException: org.hibernate.Session at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) ... 还有 13 个ClassNotFoundException: org.hibernate.Session at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) ... 还有 13 个

2012 年 6 月 21 日下午 3:39:22 org.apache.catalina.core.StandardWrapperValve 调用严重:为 servlet genericActionServlet java.lang.ClassNotFoundException 分配异常:org.apache.catalina.loader.WebappClassLoader.loadClass 的 org.hibernate.Session (WebappClassLoader.java:1358) 在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) 在 br.com.flex4j.servlet.genericActionServlet.init(genericActionServlet.java:29) 在 org.apache。 catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161) 在 org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 129) 在 org.apache.catalina.core.org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)。StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org .apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263) 在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process (Http11Protocol.java:584) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 处的连接器.CoyoteAdapter.service(CoyoteAdapter.java:263) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java: 584)在 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)在 java.lang.Thread.run(未知来源)org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 处的连接器.CoyoteAdapter.service(CoyoteAdapter.java:263) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java: 584)在 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)在 java.lang.Thread.run(未知来源)

编辑:

我的项目的类路径:属性>java构建路径

4

3 回答 3

4

据我了解,您提供的类路径 xml 由 Eclipse 使用,它与您的 Web 应用程序类路径无关。您收到 NoClassDefFoundError 的原因是 Tomcat 无法找到 Hibernate 类。确保您的 Web 模块在 WEB-INF/lib 目录中具有所有必需的 jar。

于 2012-06-21T19:47:42.833 回答
0

将所有 JARS 添加到 WEB-INF 并在项目上执行构建路径。

于 2014-06-13T18:57:32.497 回答
0

要在 Eclipse 中添加 jar,您有两种选择:

右键单击项目到属性->单击java构建路径->配置构建路径->库->并选择添加外部jar按钮。它将打开一个窗口,您可以在其中添加所需的所有罐子。

第二种选择是将 jar 直接粘贴到 lib 文件夹。lib 文件夹位于 Web Content --> WEB-INF --> lib 中。

使用其中任何一种。

于 2017-12-09T08:08:20.030 回答