This chapter discusses what goes into an XML deployment descriptor; it teaches you how to write deployment descriptors for your beans. Keep in mind that you may never need to write a deployment descriptor by hand; most vendors of integrated development tools and EJB servers will provide tools for creating the descriptor automatically. Even if you have such a tool available, however, you should be familiar enough with deployment descriptors to be able to read them on your own.
This chapter does not attempt to teach you how to read or write
correct XML. There are
many books on the subject: a good quick reference is XML
Pocket Reference
by Bob
Eckstein (O’Reilly); XML in a Nutshell, by
Elliotte Rusty Harold and W. Scott Means (O’Reilly), provides a
more detailed treatment. Very briefly, XML looks like HTML, but with different tag
names and different attributes inside the tags. You won’t see
<h1>
and <p>
inside
a deployment descriptor; you’ll see tags like
<ejb-jar>
. But otherwise, if you expect an
XML document to look like HTML, you’re most of the way toward
reading it. The tag names and attribute names for an XML document are
defined by a special document called a
Document Type Definition (DTD). Therefore,
for XML deployment descriptors, there is a DTD that defines the tags
and attributes that can be used in the document; the DTDs for
deployment descriptors in EJB 2.0 and 1.1 are available online at
http://java.sun.com/dtd/ejb-jar_2_0.dtd and http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd.
There are a few other important differences between XML and HTML. XML
is much more strict; many things that are acceptable in HTML are
errors in XML. This should not make a difference if you’re just
reading a deployment descriptor, but if you’re writing one, you
have to be careful. Two differences are particularly important.
First, XML is case-sensitive. You cannot mix uppercase and lowercase
in your tag names. HTML does not care about the difference between
<h1>
and <H1>
, but
XML does. All the tags and attributes used in deployment descriptors
are lowercase. Second, XML will not forgive you if you fail to supply
closing tags. In HTML you can write
<p>...<p>
, without ever putting in a
</p>
to end the first paragraph. XML never
allows you to be sloppy. Whenever you have an opening tag, there must
always be a closing tag.
That’s about it. These few paragraphs don’t even qualify as a quick introduction to XML, but the basic ideas are very simple, and that’s really all you should need to get going.