2016-12-24 85 views
0

我正在用eibernate作为ORM框架在eclipse中开发struts2框架中的web模块和ejb模块。java.lang.ClassNotFoundException:部署EAR时发生org.hibernate.HibernateException

每当我修改我的ejb模块时,我必须将它打包到jar中,并将其包含在我的web模块/WEB-INF/lib文件夹中以运行我的整个应用程序。

虽然这种方式的应用程序运行良好,但它非常耗时。所以我试图将它们映射到EAR模块中。但是当我尝试运行EAR模块时。

它给下面的例外

2016-12-24 13:23:43,992 ERROR [org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler] (default task-4) Exception occurred during processing request: WFLYEJB0442: Unexpected Error: javax.ejb.EJBException: WFLYEJB0442: Unexpected Error 
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:184) 
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277) 
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327) 
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239) 
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) 
    at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) 
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) 
    at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:47) 
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) 
    at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100) 
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) 
    at org.jboss.as.ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22) 
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) 
Caused by: java.lang.NoClassDefFoundError: org/hibernate/HibernateException 
    at com.ebs.persistence.dao.UserDao.<clinit>(UserDao.java:16) 
    at com.ebs.business.service.UserAuthorisationBusinessService.getUserProfile(UserAuthorisationBusinessService.java:28) 
    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) 
Caused by: java.lang.ClassNotFoundException: org.hibernate.HibernateException from [Module "deployment.EBS.ear.EBS-ejb.jar:main" from Service Module Loader] 
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351) 
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93) 
    ... 179 more 

下面是我怀疑得到的异常

private static SessionFactory sessfct = SessionFactoryGenerator.getSessionFactory(); 

这似乎是一些问题与classloader.Somehow它是无法加载hibernatecore.jar 。早些时候,当EAR不在图片中时,它使用相同的一组瓶子很好地工作。我是EAR新手。下面是application.xml中

<module> 
    <web> 
     <web-uri>EBS-web.war</web-uri> 
     <context-root>EBS-web</context-root> 
    </web> 
    </module> 
    <module> 
    <ejb>EBS-ejb.jar</ejb> 
    </module> 

我也试过,包括EAR lib文件夹中所有的罐子,但达到

回答

0

我开发在Struts2框架和EJB模块Web模块没有成功的结构使用hibernate作为ORM框架使用eclipse 。每当我修改我的 ejb模块时,我必须将它打包成jar,并将其包含在我的web module/WEB-INF/lib文件夹中,以便运行我的整个应用程序。

使用Eclipse插件作为WTP,您不应该有这个问题。

我也试过,包括在EAR的lib文件夹中所有的罐子,但没有成功 达到

如果你把jar文件放到EAR,他们应该是在APP-INF/lib夹在的根耳。

此外,您可以使用构建工具作为Maven或Gradle。它可以减轻你的包装工作。