[ Pobierz całość w formacie PDF ]
.Later on, we'll addentries for numerous other entity beans that we will code and add to the application.Becausewe are deploying a CMP bean, the fields that must be handled by the container are listed; inthis case, these are all the fields in the OfficeBean class.We also give the bean a name to beused, OfficeBean.If you are familiar with EJB deployment descriptors, you might notice that I have left out theassembly-descriptor element and related subelements that allow permission specificationfor beans and their methods.That's so you can focus on the bean right now, and deal with66Building Java"! Enterprise Applications Volume I: Architecturesecurity later.Don't worry, though; I'll get to all of this before we're done with ourapplication.Leaving it out for now will allow the container to generate default permissions.Example 4-7.The Office Entity Bean Deployment DescriptorThis Office bean represents a Forethought office,including its location.OfficeBeanOfficeBeancom.forethought.ejb.office.OfficeHomecom.forethought.ejb.office.Officecom.forethought.ejb.office.OfficeLocalHomecom.forethought.ejb.office.OfficeLocalcom.forethought.ejb.office.OfficeBeanContainerjava.lang.IntegerFalseOFFICESidcitystateidA word to the wise here: it might seem that the XML would be clearerwith some reorganization.For example, the prim-key-class elementmight be easier to find if it were right below the other class entries(home, remote, and ejb-class).However, moving it will cause anerror in deployment! The ejb-jar_2_0.dtd file specifies the order ofelements, and is completely inflexible in this respect.This is a typicallimitation of DTDs, as opposed to other constraint representations inXML such as XML Schemas.If these elements not in the correct ordershown in the example, you will encounter errors in deployment.4.3.2 Wrapping It UpThe process of creating the Office entity bean is finally complete (at least in its current form).You now need to create a deployable JAR file, and then create the container classes to addimplementation details to your bean, such as SQL and JDBC code.First, ensure that yourdirectory structure is set up correctly.The Java source files can all be in a top-level directory.67Building Java"! Enterprise Applications Volume I: ArchitectureYou should then create a directory called META-INF/, and place the ejb-jar.xml deploymentdescriptor inside it.Next, compile your source files:galadriel:/dev/javaentI $ javac -d build \ch04/src/java/com/forethought/ejb/util/*.java \ch04/src/java/com/forethought/ejb/office/*.javaSetting up your classpath for these compilations can be either reallysimple or really difficult.Many application servers provide a script thatcan be run to set up all the environment variables.Running this scripttakes care of all the classpath issues for you, and your compilations willbe a piece of cake (refer to Appendix D and Appendix E for thesedetails for the Sun J2EE reference implementation).Or, you may haveto manually add the entries needed to your classpath.You shouldconsider creating your own script in these cases, and then botheringyour server vendor until they provide you with a prebuilt script.Unfortunately, the libraries are packaged differently with every server(for example, in Weblogic there is one giant JAR, and in jBoss there areindividual JARs for each API), so I can't tell you exactly what to type.Just look for a script; it's almost always there.Correct any errors you receive by referring to the text.Once you've compiled the source, youshould have the directory structure shown in Figure 4-2.Notice that I have build/ and deploy/directories in place before compilation and deployment to segregate my files.You shouldcreate these as well (or use your own structure, of course).Figure 4-2.Directory structure for office entity bean68Building Java"! Enterprise Applications Volume I: ArchitectureNext, you need to create a JAR file of these classes and the deployment descriptor.Create itwith the name forethoughtEntities.jar, as shown:galadriel:/dev/javaentI $ cd buildgaladriel:/dev/javaentI/build $ jar cvf./deploy/forethoughtEntities.jarcom \ META-INF/ejb-jar.xmladded manifestadding: com/(in = 0) (out= 0)(stored 0%)adding: com/forethought/(in = 0) (out= 0)(stored 0%)adding: com/forethought/ejb/(in = 0) (out= 0)(stored 0%)adding: com/forethought/ejb/office/(in = 0) (out= 0)(stored 0%)adding: com/forethought/ejb/office/Office
[ Pobierz całość w formacie PDF ]