2 Replies Latest reply on May 21, 2002 11:46 PM by robert mark waugh

    Best Practices for Packaging

    robert mark waugh Newbie

      Hello:

      Recently, I started to reevaluate how I am packaging my J2EE applications. What is the consensus around here as to the best way package your applications? If there is a published set of standardized recommendations that I am not aware of then that is enough to answer my question.

      Basically, I have up until now been packaging things like this:

      EAR : Contains one or more applications, each one made up of a single EJB Jar and a Web WAR
      WAR : Contains display logic and logic bridges to EJB's: JSP's/taglibs and Servlets
      EJB JAR: Contains non-display logic and data access objects: Entity, Session, Message, etc EJB's

      It seems to be possible to also package things in this way:

      EAR : Contains one or more applications, each one made up of multiple EJB Jar's and a Web WAR
      WAR: Contains display logic and the associated EJB's required for the web application
      EJB JAR's: Contains independent logic components from the web application being deployed. Such as decoupled third party EJB applications, etc.

      The primary difference being that the WAR contains all of the dependent code for a single web application, and the EJB JAR's containing independent EJB's that are packaged for potential redistribution.

      Now, of course your EJB's should be relatively independent as the classloaders enforce a degree of independence, but it is intuitively obvious that generally there is a dependence between the structure of your EJB's and the structure of your web application, and this holds to some degree when you invert this relationship.

      So, should those EJB's be packaged in the same WAR file as the rest of the web application, and EJB's that are entirely independent packaged in their own JAR's?

      Is there a better way of organizing your package structures that you have found to be effective? Am I grossly missing something in my assumptions?

      Thank you very much for your time,
      robert

        • 1. Re: Best Practices for Packaging
          Richard Doust Newbie

          I'd be very intersted as well. Specifically though, I have a problem accessing EJBs deployed in jars outside the war/ear. That is, I package application specific EJB in a jar, package that into a war. It requires access to EJBs that are packaged outside of the ear within which the war is packaged. I can't seem to get a manifest file set up correctly to allow the ejb in the jar in the war to find the ejb packaged outside the ear.
          Do you know how I can do this?

          • 2. Re: Best Practices for Packaging
            robert mark waugh Newbie

            > I'd be very intersted as well. Specifically though, I
            > have a problem accessing EJBs deployed in jars
            > outside the war/ear. That is, I package application
            > specific EJB in a jar, package that into a war. It
            > requires access to EJBs that are packaged outside of
            > the ear within which the war is packaged. I can't
            > seem to get a manifest file set up correctly to allow
            > the ejb in the jar in the war to find the ejb
            > packaged outside the ear.
            > Do you know how I can do this?


            I believe that you would have a hard time doing this due to the fact that the classloader for the ejb jar outside the ear would be a sibling, so you're not going to be able to resolve the classes effectively. You either need to have the jar as a part of the ear or at least the interfaces that you are dealing with in the ear. This is somewhat of a bummer, but I'm not sure of a method around this. Apparently between J2EE 1.2 and 1.3 the classloader relationships changed somewhat such that EJB's are handled through a single classloader and the WAR's are handled through child classloaders, giving the EJB's the ability to cross reference and WAR packaged classes the ability to load the EJB classes without needing to repackage the EJB classes in the WAR file.

            So, it appears that the practice that is recommended is to package EJB's outside the WAR file and everything with the EAR file.

            robert