4 Replies Latest reply on Dec 26, 2006 1:09 AM by Bustanil Arifin

    Help on EjB 3 Packaging

    Bustanil Arifin Newbie

      Hi all,

      I' ve been working my project using EJB 3 since September and I enjoy working with it. But one thing that still confuses me is how EJB 3 component should be packaged. Should I seperate Entity Classes from Session Beans in different jars? How about the directory structure?

        • 1. Re: Help on EjB 3 Packaging
          Andrew Rubinger Master

          It's probably a good practice to separate out your Entity beans into their own JAR; each persistence unit is scoped to that JAR alone per the spec.

          I generally like to give each of my "services" (which may be JMX, Stateful, or Stateless EJBs) its own JAR, each unique collection of Entity Beans per persistence unit its own JAR (read: if 3 persistence units, 3 JARs for Entities), and a "common" JAR for standard java classes. Then I throw all these into an EAR with a proper application.xml in META-INF, explicitly defining each of the components above.

          In the end, it'll come down to whatever works best for your system, and how you plan on deploying your components (All at once, always? Lots of dependencies? Or as independent modules that may be added or removed on a whim?)

          S,
          ALR

          • 2. Re: Help on EjB 3 Packaging
            Bustanil Arifin Newbie

            Thanks for your advice, ALRubinger.

            In my project, I put a session bean together with it's entity classes in one JAR file (.ejb3). So, 3 session beans means 3 .ejb3 files. I didn't throw my EJB3 files into an EAR , because i think it's not too important ;) CMIIW. I just deploy them into server directly, and it works. Any consequences of doing this?

            Best regards
            Bustanil

            • 3. Re: Help on EjB 3 Packaging
              Andrew Rubinger Master

              Sure, this is a valid setup; shouldn't be any consequences unless you eventually specify that one module depends on another, in which case you'll get errors unless they're deployed together at the same time.

              Also, EAR packaging will allow you to change up the classloading configuration, as you may run into issues down the road depending upon how your classes are being shared within your applications:

              http://www.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration

              But again, packaging is a choice that should be made based on what'll work best for you. For smaller apps I like to deploy simple JAR (or .ejb3, as you're using) archives. I like greater control over my enterprise applications at work, and those get thrown into EARs as part of the build.

              S,
              ALR

              • 4. Re: Help on EjB 3 Packaging
                Bustanil Arifin Newbie

                Hi ALRubinger,

                Currently my project has grown from 3 modules to 7 modules.
                And my entity classes that is used by more than one session bean is scattered over the 7 jar file. It makes hot deployment running slow and surely slowing the development process. So I tried your setup.

                Here's my first packaging build.xml :


                <?xml version="1.0"?>
                
                <!-- ======================================================================= -->
                <!-- JBoss build file -->
                <!-- ======================================================================= -->
                
                <project name="OLIBSE2-SERVER" default="all" basedir=".">
                
                 ......
                
                 <!-- =================================================================== -->
                 <!-- Pack the CIF Module -->
                 <!-- =================================================================== -->
                 <target name="olibse2-cif" depends="compile">
                 <jar jarfile="build/olibse2-cif.ejb3">
                 <fileset dir="${build.classes.dir}">
                 <include name="com/cip/olibse2/domain/cif/*.class" />
                 <include name="com/cip/olibse2/cif/*.class" />
                 </fileset>
                 <fileset dir="${src.resources}/">
                 <include name="META-INF/persistence.xml" />
                 </fileset>
                 </jar>
                 <copy file="build/olibse2-cif.ejb3" todir="${jboss.home}/server/default/deploy" />
                 </target>
                
                 <!-- =================================================================== -->
                 <!-- Pack the CurrentAccount Module -->
                 <!-- =================================================================== -->
                 <target name="olibse2-ca" depends="compile">
                 <jar jarfile="build/olibse2-current.ejb3">
                 <fileset dir="${build.classes.dir}">
                 <include name="com/cip/olibse2/serahterimamodal/server/domain/*.class" />
                 <include name="com/cip/olibse2/funding/saving/server/domain/*.class" />
                 <include name="com/cip/olibse2/config/server/domain/*.class" />
                 <include name="com/cip/olibse2/funding/current/server/*.class" />
                 <include name="com/cip/olibse2/funding/saving/server/domain/*.class" />
                 <include name="com/cip/olibse2/cif/server/domain/*.class" />
                 <include name="com/cip/olibse2/cif/server/OperationResult.class" />
                 <include name="com/cip/olibse2/funding/current/server/domain/*.class" />
                 <include name="com/cip/olibse2/funding/current/server/exceptions/*.class" />
                 <include name="com/cip/olibse2/approval/server/AuthSchema.class" />
                 <include name="com/cip/olibse2/security/server/User.class" />
                 </fileset>
                 <fileset dir="${src.resources}/">
                 <include name="META-INF/persistence.xml" />
                 </fileset>
                 </jar>
                 <copy file="build/olibse2-current.ejb3" todir="${jboss.home}/server/default/deploy" />
                 </target>
                
                 <!-- =================================================================== -->
                 <!-- Pack the Configuration Module -->
                 <!-- =================================================================== -->
                 <target name="olibse2-config" depends="compile">
                 <jar jarfile="build/olibse2-config.ejb3">
                 <fileset dir="${build.classes.dir}">
                 <include name="com/cip/olibse2/serahterimamodal/server/domain/*.class" />
                 <include name="com/cip/olibse2/cif/server/domain/*.class" />
                 <include name="com/cip/olibse2/funding/saving/server/domain/*.class" />
                 <include name="com/cip/olibse2/config/server/*.class" />
                 <include name="com/cip/olibse2/config/server/domain/*.class" />
                 <include name="com/cip/olibse2/cif/server/OperationResult.class" />
                 <include name="com/cip/olibse2/approval/server/AuthSchema.class" />
                 <include name="com/cip/olibse2/security/server/User.class" />
                 </fileset>
                 <fileset dir="${src.resources}/">
                 <include name="META-INF/persistence.xml" />
                 </fileset>
                 </jar>
                 <copy file="build/olibse2-config.ejb3" todir="${jboss.home}/server/default/deploy" />
                 </target>
                
                 <!-- =================================================================== -->
                 <!-- Pack the Transaction Module -->
                 <!-- =================================================================== -->
                 <target name="olibse2-tx" depends="compile">
                 <jar jarfile="build/olibse2-tx.ejb3">
                 <fileset dir="${build.classes.dir}">
                 <include name="com/cip/olibse2/serahterimamodal/server/domain/*.class" />
                 <include name="com/cip/olibse2/cif/server/domain/*.class" />
                 <include name="com/cip/olibse2/funding/saving/server/domain/*.class" />
                 <include name="com/cip/olibse2/transaction/server/*.class" />
                 <include name="com/cip/olibse2/transaction/server/domain/*.class" />
                 <include name="com/cip/olibse2/cif/server/OperationResult.class" />
                 <include name="com/cip/olibse2/approval/server/AuthSchema.class" />
                 <include name="com/cip/olibse2/security/server/User.class" />
                 </fileset>
                 <fileset dir="${src.resources}/">
                 <include name="META-INF/persistence.xml" />
                 </fileset>
                 </jar>
                 <copy file="build/olibse2-tx.ejb3" todir="${jboss.home}/server/default/deploy" />
                 </target>
                
                </project>


                As you can see, 20 classes under com/cip/olibse2/cif/server/domain/ is used on every module. So, i changed the configuration as you suggested to speed up the hot deployment:

                <!-- =================================================================== -->
                 <!-- Pack the Entity Classes -->
                 <!-- =================================================================== -->
                 <target name="olibse2-entity" depends="compile">
                 <jar jarfile="build/olibse2-entity.jar">
                 <fileset dir="${build.classes.dir}">
                 <include name="com/cip/olibse2/funding/current/server/domain/*.class" />
                 <include name="com/cip/olibse2/funding/saving/server/domain/*.class" />
                 <include name="com/cip/olibse2/cif/server/domain/*.class" />
                 <include name="com/cip/olibse2/security/server/EcUserMenu.class" />
                 <include name="com/cip/olibse2/security/server/EcUserMenuId.class" />
                 <include name="com/cip/olibse2/transaction/server/domain/*.class" />
                 <include name="com/cip/olibse2/config/server/domain/*.class" />
                 <include name="com/cip/olibse2/serahterimamodal/server/domain/*.class" />
                 </fileset>
                 <fileset dir="${src.resources}/">
                 <include name="META-INF/persistence.xml" />
                 </fileset>
                 </jar>
                 <copy file="build/olibse2-entity.jar" todir="${jboss.home}/server/default/deploy" />
                 </target>
                
                 <target name="olibse2-cif-service" depends="compile">
                 <jar jarfile="build/olibse2-cif-service.jar">
                 <fileset dir="${build.classes.dir}">
                 <include name="com/cip/olibse2/cif/server/*.class" />
                 <include name="com/cip/olibse2/cif/server/exceptions/*.class" />
                 <include name="com/cip/olibse2/approval/server/AuthSchema.class" />
                 </fileset>
                 <fileset dir="${src.resources}/">
                 <include name="META-INF/persistence.xml" />
                 </fileset>
                 </jar>
                 <copy file="build/olibse2-cif-service.jar" todir="${jboss.home}/server/default/deploy" />
                 </target>
                
                 .... // other services
                
                


                The new configuration really made the hot deployment alot faster :D. But one big problem arose :(. The session bean in olibse2-cif-service.jar cannot found the entities which was packed in olibse2-entity.jar. I'have tried using ear configuration with an application.xml, but it didn't solve the problem. Is there anything I missed? Please help.

                Best regards,
                Bustanil