To separate code from configuration.
You can easily change Datasource, EJB without code modification.
- you want to change datasource for your application, thanks to ENC JNDI you
can do it without modifing code and recompiling, just edit xml file,
- you can write complete EJB and test it without complete design of whole
application (you don't have to know exact JNDI name of EJB),
- it's easy to write GUI application for configuring J2EE applications -
everything is in XML files not in code,
- and many, many, other reasons.
Look at Development Roles of J2EE application, especially "* Developer",
"Application Assembler", "Application Deployer and Administrator".
Someone else writes the code and someone else configures. "Application
Assembler" and "Application Deployer and Administrator" theoretically even
don't have to know Java :)