facebook

Sharing classes between EJB-JAR & WEB-WAR

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #200998 Reply

    nalbion
    Member

    I think that I’m doing something fundamentally wrong here.
    I have a ValueObject “User” that I want to access from both the EJBs and JSPs/Servlets.

    Because MyEclipse has created 2 separate directories for the EJB project and the WAR project, I get all sorts of problems unless I copy the VO class into both project directories – but this becomes awkward to maintain if the VO changes.

    There must be a better way?

    #201007 Reply

    Scott Anderson
    Participant

    There must be a better way?

    Sure there is. I’d suggest creating an EAR project. Then, right-click on it and your EJB and WAR projects to it. You can then remove your value object from your WAR project since the classloader hierarchies that EAR’s use will make the ValueObject class in your EJB jar available to your war as needed.

    –Scott
    MyEclipse Support

    #201282 Reply

    just my two cents….

    another way is to pack all the common classes in a jar and then include that jar in both projects 🙂

    Another thing I have done is to put the compiled classes under APP-INF/classes in the EAR’s hierarchy.

    You can also put a jar containing the common classes under APP-INF/lib in the EAR’s hierarchy

    Saludos

    #201294 Reply

    support-michael
    Keymaster

    A couple of thoughts:

    1) I’m not a big fan of maintaining and copying jars around. Its too easy to introduce a versioning problem. For example I helped resolve a database driver version incompatibility problem last year where there were several classes.zip/jar files copied among a dozen projects that were deployed as an EAR. The only problem is that they were not all the same version and 1 of them was corrupting a client’s Oracle database. It took me quite a while to figure this out since the behavior was so intermittent.

    So I set up my EJB projects to hold all DO/VO objects transfered from the biz server tier to the web tier. This assumes that the web module and ejb modules will be deployed as part of the same EAR. The MyEclipse EAR project creation mechanism sets up a classpath dependencies from Web Modules to EJB Modules analogous to the manner in which J2EE hierarchical classloader behaviors. This is one reason that MyEclipse does not support nested modules within an EAR project like some other OSS Eclipse products have tried. The advantage of the MyEclipse model is that you are able to discover at design time if you have partitioned your modules correctly. Otherwise you’re stuck diagnosing more costly runtime classnotfound exceptions.

    2)

    Another thing I have done is to put the compiled classes under APP-INF/classes in the EAR’s hierarchy.

    You can also put a jar containing the common classes under APP-INF/lib in the EAR’s hierarchy

    This approach is Weblogic8 specific and not portable to other J2EE servers.

    Michael
    MyEclipse Support

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Sharing classes between EJB-JAR & WEB-WAR

You must be logged in to post in the forum log in