1 Reply Latest reply on Oct 24, 2005 11:17 AM by dornus

    Help with weird ClassLoader error

    dornus Novice

      I am trying to send emails using JMS. I have the following setup

      EAR
      |--MyHelperBeans.ejb
      | |--MyEmailObj
      |
      |--MyEJB3.ejb3
      | |--MyEmailService
      | |--MyEJB3Class


      The code for my Email Service using JMS is shown below. You can see that the email service is receiving a custom serializable object (a.k.a. MyEmailObj)

      package ejb3.MyEmailService;
      
      import ejb.MyEmailObj;
      
      import javax.ejb.ActivationConfigProperty;
      import javax.ejb.MessageDriven;
      import javax.jms.ObjectMessage;
      
      @MessageDriven(activateConfig =
       {
       @ActivationConfigProperty(propertyName = "destinationType",
       propertyValue = "javax.jms.Queue"),
       @ActivationConfigProperty(propertyName = "destination",
       propertyValue = "queue/myEmailQueue")
       })
      public class EmailService {
      
       public void onMessage(javax.jms.Message msg) {
       try {
       System.out.println("I am in onMessage()");
       final ObjectMessage objMessage = (ObjectMessage) msg;
       final MyEmailObj email = (MyEmailObj) objMessage.getObject();
       System.out.println("I should get here");
       }
       catch (Exception e) {
       System.out.println("Error in onMessage().");
       System.out.println(e.toString());
       e.printStackTrace();
       }
       }
      }
      


      However, it seems that it cannot find ejb3 classes referenced from within MyEmailObj. Below is the code for MyEmailObj.

      public class MyEmailObj implements Serializable {
      
       private boolean myBoolean;
      
       MyEJB3Class myEJB3Class;
      
       public EmailObj() {
       try{
       System.out.println("MyEmailObj Constructor");
       InitialContext ctx = new InitialContext();
       myEJB3Class = (MyEJB3Class)ctx.lookup(MyEJB3Class.class.getName());
       }
       catch(Exception e){
       System.out.println("Could not get MyEJB3Class.");
       e.printStackTrace();
       }
       }
      
       public void setMyBoolean(final boolean b) {
       myBoolean = myEJB3Class.doSomething(b);
       }
      }
      


      When I execute the program I get the following:

      [STDOUT] MyEmailObj Constructor
      [STDOUT] I am in onMessage()
      [STDOUT] Error in onMessage().
      [STDOUT]javax.jms.MessageFormatException: ClassNotFoundException: No ClassLoaders found for: ejb3.MyEJB3Class
      [STDOUT] javax.jms.MessageFormatException: ClassNotFoundException: No ClassLoaders found for: ejb3.MyEJB3Class
      [STDOUT] at org.jboss.mq.SpyObjectMessage.getObject(SpyObjectMessage.java:136)
      [STDOUT] at ejb3.services.email.EmailService.onMessage(EmailService.java:26)
      [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)
      [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
      [STDOUT] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:32)
      [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      [STDOUT] at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:113)
      [STDOUT] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:138)
      [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      [STDOUT] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
      [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      [STDOUT] at org.jboss.ejb3.mdb.MDB.localInvoke(MDB.java:716)
      [STDOUT] at org.jboss.ejb3.mdb.MDB$MessageListenerImpl.onMessage(MDB.java:912)
      [STDOUT] at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:256)
      [STDOUT] at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:904)
      [STDOUT] at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:160)
      [STDOUT] at org.jboss.mq.SpySession.run(SpySession.java:333)
      [STDOUT] at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:180)
      [STDOUT] at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
      [STDOUT] at java.lang.Thread.run(Thread.java:595)