Building an EJB component involves more than just writing Java code. You need to compile, package, configure, and deploy—missing any step results in a non-functional component. What’s the correct order?
The EJB development lifecycle is an 8-step process from raw Java files to a running, tested component in the container. Each step has a specific purpose and must be done in order.
- Write Java files: Component interfaces, home interfaces, bean class, helper classes
- Write deployment descriptor:
ejb-jar.xmlwith bean metadata (or use IDE/XDoclet to generate) - Compile:
javacto convert.java→.class - Create EJB-JAR: Use
jarutility to package.classfiles +ejb-jar.xml - Deploy: Copy JAR to container’s deployment folder or use vendor tools
- Configure: Set database connections, thread pools via vendor console/config files
- Start container: Verify the JAR loaded successfully
- Test: Write a client, generate stubs, compile, run, and verify
- Standardized process: Every EJB component follows these steps (vendor-neutral)
- Step 5 is vendor-specific: Each container has its own deployment mechanism
- Step 6 is vendor-specific: Configuration differs (Web console vs config files)
- Deployment descriptor is key: Tells container how to manage the bean
- Built from: Deployment Descriptor, Home Interface, Remote Interface
- Builds into: EJB Object (generated in step 5), EJB Container
- Related: EJB-JAR File (output of step 4)
- Contrasts with: Simple Java app (just compile and run—no deployment descriptor needed)
- Forgetting step 2: Without
ejb-jar.xml, container doesn’t know about your beans - Classpath issues: Step 3 needs EJB APIs (javax.ejb.*) in classpath
- Vendor tools automate: Modern IDEs (Eclipse, IntelliJ) automate steps 2-4