如何让JBoss Quartz作业看到我的JAR文件中的类?

时间:2012-08-17 16:56:02

标签: jboss classloader quartz-scheduler

我正在使用JBoss 4.2.3.GA并部署一个使用Hibernate 4.1.5.SP1的JAR应用程序。在我的JAR中,我有一个Quartz作业,配置如此......

@MessageDriven(activationConfig = {@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0 40 12 * * ?")})
@ResourceAdapter("quartz-ra.rar")
@Depends({
"jboss.ejb:service=EJBTimerService"})
public class UpdateOrgsJob implements Job {

我认为JBoss在一个单独的类加载器中加载Quartz而不是引用我的JAR类,因为我得到错误“java.lang.NoClassDefFoundError:net / sf / ehcache / CacheException”,即使它在我的JAR文件中。如何使我的JAR类对Quartz可见?

以下是完整的堆栈跟踪......

javax.ejb.EJBTransactionRolledbackException: java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException^M
        at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)^M
        at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)^M
        at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)^M
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)^M
        at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)^M
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)^M
        at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:249)^M
        at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)^M
        at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)^M
        at $Proxy90.execute(Unknown Source)^M
    at org.jboss.resource.adapter.quartz.inflow.QuartzJob.execute(QuartzJob.java:57)^M
        at org.quartz.core.JobRunShell.run(JobRunShell.java:203)^M
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)^M
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException^M
        at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:174)^M
        at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)^M
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)^M
        at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)^M
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)^M
        at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)^M
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)^M
        at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)^M
        ... 11 more^M
Caused by: java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException^M
        at java.lang.Class.getDeclaredConstructors0(Native Method)^M
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)^M
        at java.lang.Class.getConstructor0(Class.java:2699)^M
        at java.lang.Class.newInstance0(Class.java:326)^M
        at java.lang.Class.newInstance(Class.java:308)^M
        at org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:375)^M
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:245)^M
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)^M
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)^M
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)^M
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)^M
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)^M
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)^M
        at org.mainco.subco.orgsclient.service.AbstractTransactionService.startOperation(AbstractTransactionService.java:27)^M
        at org.mainco.subco.orgsclient.service.OrganizationServiceImpl.saveOrganization(OrganizationServiceImpl.java:87)^M
        at org.mainco.subco.orgsclient.service.OrganizationServiceImpl.getEODBOrganizations(OrganizationServiceImpl.java:221)^M
        at org.mainco.subco.orgsclient.service.OrganizationServiceImpl.saveOrgsFromWebService(OrganizationServiceImpl.java:183)^M
        at org.mainco.subco.orgsclient.quartz.UpdateOrgsJob.execute(UpdateOrgsJob.java:55)^M
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)^M
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)^M
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)^M
        at java.lang.reflect.Method.invoke(Method.java:597)^M
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)^M
        at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)^M
        ... 18 more^M
Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: net.sf.ehcache.CacheException^M
        at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)^M
        at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521)^M
        at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)^M
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)^M
        ... 42 more^M

1 个答案:

答案 0 :(得分:1)

你可以把你的ehcache jar文件放在$ {jboss.server} / lib中,或者你也可以试试Jboss wiki

中提到的2种方法
1.  Delay  Quartz service startup
2.  set <attribute name="UseJBossWebLoader">true</attribute>