fundamental j2ee classpath question


General J2EE: fundamental j2ee classpath question

  1. fundamental j2ee classpath question (1 messages)

    hi folks -- I have a j2ee project with - a WAR (which has among other things a servlet in it) - a ejb project (which has a stateless session bean in it) I need to call the session bean from the servlet and my servlet code gets a reference to the bean via jndi as follows ...skipping jndi stuff ... LoadTimerTaskHome loadTimerTaskHome = (LoadTimerTaskHome)PortableRemoteObject.narrow( timerHomeObject, LoadTimerTaskHome.class); However, at compile time, LoadTimerTaskHome (the home interface of the bean) can't be resolved in the servlet class. Which makes sense cuz how would the servlet class know about the bean class? And that's the question: At *compile* time, how can i make classes in my WAR aware of classes in my EJB proj, which are deployed to the same EAR? There must be a very simple J2EE way of doing this... I'm not an EJB person, so i'm just confused about what is probably extremely basic.... thx VERY much for any insights...
  2. First you need to know the concept of layers. You WAR should be the presentation/UI tier while your EJB should be your business logic tier. WAR depends on EJB. At compile time, you should setup your 2 projects' dependency so that WAR project depends on EJB project. Then you will have no compile issue. At runtime, your EAR includes both WAR and EJB. How they share common classes like the EJB home interface depends on your application server. Usually application servers will create one top level class loader for the EAR and one separate child class loader for each WAR and EJB. EJB usually is deployed before WAR. Or you can also include the home interface into your WAR. But this may create double classes. You need to check your application server regarding this.