java.lang.NoClassDefFoundError:org / hibernate / MappingException

时间:2014-02-11 05:25:41

标签: java hibernate struts

启动Apache Tomcat服务器时出现以下错误。我已经将Struts与Hibernate框架集成在一起。

有人能告诉我这个例外的原因吗?

启动服务器时出现PFA异常日志?

Feb 11, 2014 10:46:09 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\eclipse-standard-kepler-R-win32\eclipse;;.
Feb 11, 2014 10:46:09 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsOne' did not find a matching property.
Feb 11, 2014 10:46:09 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 11, 2014 10:46:09 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 766 ms
Feb 11, 2014 10:46:09 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 11, 2014 10:46:09 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
Feb 11, 2014 10:46:10 AM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/C:/Users/Mohit/workspace/Struts/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/StrutsOne/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml
Feb 11, 2014 10:46:10 AM org.apache.struts.action.ActionServlet init
SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable.  Most likely, this is due to an incorrect or missing library dependency.
java.lang.NoClassDefFoundError: org/hibernate/MappingException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:172)
    at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:147)
    at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:842)
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:359)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4420)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4733)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.hibernate.MappingException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    ... 27 more

2 个答案:

答案 0 :(得分:0)

如果您在eclipse中工作,则应在Web项目类路径中添加hibernate jar并部署程序集。

通过右键单击项目来执行此操作 - >属性 - >部署程序集,并添加jar。 或(如果jar位于WEB-INF / lib文件夹中) 右键单击项目 - >属性 - > java构建路径 - >选择“libraries”选项卡,然后添加库,并选择weba bb库

答案 1 :(得分:0)

你问的是这个例外的原因。

请查看日志告诉我们的内容,

“由于意外异常或抛出错误而无法初始化Struts ActionServlet,因此将servlet标记为不可用。很可能,这是由于库依赖项不正确或缺失”

启动服务器时,通过删除war文件手动部署应用程序,或者通过eclipse工作,应用程序的第一个入口点是部署描述符,即 web.xml 。在这里,您已将servlet定义为Struts Action Servlet,因此将尝试初始化Struts ActionServlet。

现在,在你的struts-config.xml中,你可能会有这样的东西,

<struts-config>
....
    <plug-in className="com.example.MyHibernatePlugin">
        <set-property property="path" value="/hibernate.cfg.xml"/>
    </plug-in>
....
<struts-config>

com.example MyHibernatePlugin.java

import org.apache.struts.action.PlugIn;
public class HibernatePlugin implements PlugIn { ....{your code} }

话虽如此,现在你的日志正试图说明为什么在尝试初始化Struts Action Servlet时它会获得映射异常。

您必须在类路径中拥有与Struts和Hibernate相关的所有库。 不要一次添加所有内容,逐个添加,查看它抱怨的jar,然后添加,直到它停止抱怨。