3 Replies Latest reply on Dec 18, 2001 8:37 AM by Frank Griffin

    ClassNotFoundException Please Help

    Christopher R. Gardner Newbie

      I have an entity bean that, when invoked by a non-bean client, runs perfectly. However, when I try to invoke that same entity bean with a session bean, I get a ClassNotFoundException. It must be something with my setup, but I've no idea what. BTW, this is the oft-tried Monson-Haefel Cabin and TravelAgent bean example. I've posted this before, but I haven't got any pointers to really solving this problem. Here's the relevant stuff:

      server.log
      ***************************************************
      [2001-12-12 21:10:26,800,Default,INFO] Trying to get Context
      [2001-12-12 21:10:26,800,Default,INFO] Got Context
      [2001-12-12 21:10:26,860,TxCapsule,DEBUG] setRollbackOnly(): Entered, tx=XidImpl [FormatId=257, GlobalId=0htrz//1028, BranchQual=] status=STATUS_ACTIVE
      [2001-12-12 21:10:26,860,TxCapsule,DEBUG] rollback(): Entered, tx=XidImpl [FormatId=257, GlobalId=0htrz//1028, BranchQual=] status=STATUS_MARKED_ROLLBACK
      [2001-12-12 21:10:26,860,StatelessSessionContainer,ERROR] invoke returned an exception
      java.rmi.ServerException: null
      Embedded Exception
      null; nested exception is:
      javax.ejb.EJBException: null
      Embedded Exception
      null
      javax.ejb.EJBException: null
      Embedded Exception
      null
      at com.titan.travelagent.TravelAgentBean.listCabins(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:569)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:67)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:156)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:65)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:131)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:280)
      at org.jboss.ejb.Container.invoke(Container.java:528)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:411)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
      at sun.rmi.transport.Transport$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Unknown Source)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
      java.lang.ClassNotFoundException: com.titan.cabin.CabinHomeRemote
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
      at java.io.ObjectInputStream.inputProxyClassDescriptor(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.io.ObjectInputStream.inputObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.rmi.MarshalledObject.get(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:369)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:349)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:437)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:473)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:349)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at com.titan.travelagent.TravelAgentBean.getHome(Unknown Source)
      at com.titan.travelagent.TravelAgentBean.listCabins(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:569)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:67)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:156)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:65)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:131)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:280)
      at org.jboss.ejb.Container.invoke(Container.java:528)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:411)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
      at sun.rmi.transport.Transport$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Unknown Source)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)

      ***************************************************

      ejb-jar.xml
      ***************************************************
      <ejb-jar>
      <enterprise-beans>

      <ejb-name>TravelAgentEJB</ejb-name>
      com.titan.travelagent.TravelAgentHomeRemote
      com.titan.travelagent.TravelAgentRemote
      <ejb-class>com.titan.travelagent.TravelAgentBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <ejb-ref>
      <ejb-ref-name>ejb/CabinHomeRemote</ejb-ref-name>
      <ejb-ref-type>Entity/</ejb-ref-type>
      com.titan.cabin.CabinHomeRemote
      com.titan.cabin.CabinRemote
      </ejb-ref>

      </enterprise-beans>


      ***************************************************

      jboss.xml
      ***************************************************

      <enterprise-beans>

      <ejb-name>TravelAgentEJB</ejb-name>
      <ejb-ref>
      <ejb-ref-name>ejb/CabinHomeRemote</ejb-ref-name>
      <jndi-name>CabinEJB</jndi-name>
      </ejb-ref>

      </enterprise-beans>

      ***************************************************

      TravelAgentBean.java
      ***************************************************

      package com.titan.travelagent;

      import com.titan.cabin.CabinRemote;
      import com.titan.cabin.CabinHomeRemote;
      import java.rmi.RemoteException;
      import javax.naming.InitialContext;
      import javax.naming.Context;
      import java.util.Properties;
      import java.util.Vector;
      import javax.rmi.PortableRemoteObject;
      import javax.ejb.EJBException;

      public class TravelAgentBean implements javax.ejb.SessionBean {
      public void ejbCreate() {}

      public String[] listCabins(int shipId, int bedCount) {
      try {
      CabinHomeRemote home = getHome();
      Vector vect = createCabinList(home, shipId, bedCount);
      return createStringList(vect);
      } catch (Exception e) {
      throw new EJBException(e);
      }
      }

      private CabinHomeRemote getHome() throws Exception {
      System.out.println("Trying to get Context");
      javax.naming.Context jndiContext = new InitialContext();
      System.out.println("Got Context");
      Object obj = jndiContext.lookup("java:comp/env/ejb/CabinHomeRemote");

      System.out.println("Got home");
      return (CabinHomeRemote) PortableRemoteObject.narrow(obj,
      CabinHomeRemote.class);
      }

      private Vector createCabinList(CabinHomeRemote home, int shipId,
      int bedCount) throws Exception {
      Vector vect = new Vector();

      for (int i = 1;;i++) {
      CabinRemote cabin;
      try {
      cabin = home.findByPrimaryKey(new Integer(i));
      } catch (javax.ejb.FinderException e) {
      break;
      }

      if (isCriteriaMatch(cabin, shipId, bedCount)) {
      createEntry(vect, cabin);
      }
      }

      return vect;
      }

      private boolean isCriteriaMatch(CabinRemote cabin, int shipId,
      int bedCount) throws Exception {

      return cabin.getShipId() == shipId && cabin.getBedCount() == bedCount;
      }

      private void createEntry(Vector vect, CabinRemote cabin)
      throws Exception {

      String details = cabin.getShipId() + ", " + cabin.getName() + ", "
      + cabin.getDeckLevel();
      vect.addElement(details);
      }

      private String[] createStringList(Vector vect) {
      String[] list = new String[vect.size()];
      vect.copyInto(list);

      return list;
      }

      public void ejbRemove() {}
      public void ejbActivate() {}
      public void ejbPassivate() {}
      public void setSessionContext(javax.ejb.SessionContext cntx) {}
      }
      ***************************************************

        • 1. Re: ClassNotFoundException Please Help
          Fusayuki Minamoto Apprentice

          I don't know what's happening in your programs but let me say just two points:

          1) In ejb-jar.xml, "<ejb-ref-type>Entity/</ejb-ref-type>" should be "<ejb-ref-type>Entity</ejb-ref-type>".

          2) Your stack trace shows "Unknown Source" at TravelAgentBean.listCabins().
          Please compile your programs with "-g".

          Miki

          • 2. Re: ClassNotFoundException Please Help
            Christopher R. Gardner Newbie

            Thanks for the tips. I did fix the "Entity/" problem and now compile with the debug flag set. However, the outcome is the same. I'm trying to trace the path:

            1. CabinBean and supporting classes and descriptors are successfully deployed. I can run a non-bean client that creates CabinBeans. The database is updated.

            2. TravelAgentBean and supporting classes and descriptors are successfully deployed. I run a client that communicates with an object that implements the TravelHomeRemote interface. That object does communicate with the TravelAgentBean. TravelAgentBean tries to get the Home interface (CabinHomeRemote) for the CabinBean. Result: java.lang.ClassNotFoundException: com.titan.cabin.CabinHomeRemote

            Why can't this class be found?

            * Is it because my jboss.xml or other descriptor is messed up?
            * Is it because I'm supposed to set a classpath to the deployment directory?
            * Am I supposed to do more than just copy the jar files to the deployment directory?

            I'm at my wits' end on this.

            • 3. Re: ClassNotFoundException Please Help
              Frank Griffin Novice

              The JBoss Documentation has a section on running the examples from the O'Reilly EJB book where you got the CabinBean example. Apparently some tweaks are necessary to run these under JBoss. If you haven't checked this already, it might help.