JAR Files, WAR Files, and EAR
Oracle Application Server Tips by Burleson
To deploy EJBs and other components in the
J2EE application, you must package them. In keeping with J2EE
modular programming methodology, all parts of a module are packaged
together. This includes JSP files, images, utility classes, and
whatever is required to make that component a self-contained
package. JAR files, or Java Archives, are really just zipped
archives of files ending in the .jar extension. In fact, you can
pack and unpack a JAR file with any zip utility. Java provides a
utility for creating archives, called jar, that has the advantage of
creating a Manifest automatically. By creating an archive of the
required class file and other supporting files (like images,
bitmaps, etc.), you package everything into one neat file. An entire
application can be packaged into a JAR file that the Java Virtual
Machine will execute. This allows you to deploy applications in one
file. The JAR file maintains the file?s subdirectories there by
maintaining Java package integrity. Standard JavaBeans and
Enterprise JavaBeans, mentioned earlier, are packaged into JAR
WAR files are Web Application Archives. WAR
files are JAR files that end in .war and are used to package and
deploy web components into web containers. They can contain HTML
documents, servlets, JSPs, or even applet class files. WAR archives
also contain an XML file called a deployment descriptor that
describes the components. This file is normally called web.xml.
An EAR file is an Enterprise Archive and is
used to package modules of a J2EE application. An EAR file is a JAR
file that ends in .ear and can contain JAR and WAR files in addition
to any other file required by the module. EAR archives also contain
a file describing their contents?called an application descriptor,
As with all zip files, Java archives
maintain subdirectories and thus package scope. To create these
files manually, you use the Java packager tool called jar.
jar ?cvf archive_name.war
Almost all IDEs, such as JDeveloper,
automate the creation of these archives and their deployment into
established, J2EE is a set of Java technologies designed to assist
in the implementation of large, distributed, multitiered
applications from the client back to the database connection?in
other words, enterprise applications. J2EE includes a wide range of
components that support security, messaging, transactional
integrity, sending e-mail, processing XML, and more. The Java 2
Platform, Standard Edition Software Development Kit (J2SE SDK) is
the basic Java language and is required to run J2EE. The J2EE SDK
provides the specifications and APIs (Application Programming
Interface) to build J2EE applications. In addition to defining the
EJB specification, J2EE provides APIs to support a number of
technologies, discussed next.
Java Database Connectivity
The Java Database Connectivity (JDBC) API
defines methods for connecting and accessing a database within the
Java language. Most major databases, such as Oracle?s, come with
JDBC drivers. The JDBC API allows complete access to the database,
including data definition and data manipulation. The JDBC also
supports bulk inserts, bind variables, and prepare statements.
Entity EJBs (discussed later in the chapter) have built-in
connectivity with the database provided by the container; however,
if you override the container-maintained persistence, you must use
the JDBC API. Also, any bean that is not an entity EJB must use the
JDBC API to connect to a database.
Java Message Service
The Java Message Service (JMS) allows J2EE
components to create, send, receive, and read messages. By
implementing JMS, a distributed component can process messages
asynchronously, thereby improving the reliability of the distributed
action. JMS allows for loose coupling of components. JMS is used by
message-driver EJBs and provides a publish and subscribe
(topic-based) model and also a point-to-point (queue-based) model
for messaging flexibility.
Java Naming and Directory Interface
The Java Naming and Directory Interface (JNDI)
provides methods for finding objects by using attributes. This is
how EJBs and other registered objects are located inside a
container. A container can list the EJBs that it holds with JNDI so
that other components can locate them. When you deploy an archive
into a container, you may need to identify what JNDI resource it
uses. The JNDI can be used to interface with other naming
directories such as LDAP (Lightweight Directory Access Protocol).
Using JNDI, a J2EE application can coexist with legacy systems.
Java Transaction API
Database administrators understand
transactions, but many developers do not. When the application
accesses the database, it will return only committed data. For
simple updates, inserts, or deletes, committing or rolling back data
can be handled easily by the application either manually or using
autocommit. If the application conducts multiple database operations
that are interdependent, you will need to use the JTA to
demarcate the transaction limits so that the entire transaction is
committed or rolled back together.
Implementing the JavaMail API allows the
application to send e-mail notifications. Using JavaMail, an
application can notify an administrator when problems or errors are
encountered. JavaMail can also be used to provide standard
performance statistics at periodic intervals and to integrate e-mail
into an application.
Java API for XML Processing
XML (Extensible Markup Language) is an
effective way to write out data in a structured hierarchy. Almost
all of the configuration files used by the Application Server are
XML documents. (Some components that were brought into the
Application Server do not use XML, such as the http.conf file for
OHS, which came from the Apache web server.) An example of an XML
configuration file is the web.xml deployment descriptor stored in a
WAR file. As you work with XML parameter files, you need to
understand two important requirements of XML: it is case sensitive,
and it must have an ending tag.
Here is an example of an XML file that
defines three servlets?intro, timer, and recTime:
<!-- every minute -->
Each servlet has a servlet-name tag and a
servlet-class tag defining the name and class file for each servlet.
The timer servlet also has a few parameters defined. The time
parameter defines a temp file to store information as /tmp/timer.properties.
The other parameter defines the number of Timer ticks to count, in
this case 60,000, or every minute. Notice that each tag has a
Because XML produces ?well-formed? text
documents, it is a great way to pass information between different
platforms or systems. J2EE provides native support to both create
and read XML documents. Both J2EE and Oracle Application Server 10g
use XML extensively, so as an administrator, you will need to have a
basic understanding of XML.
Java Authentication and Authorization
The Java Authentication and Authorization
Service (JAAS) API supports user (or groups of users) authorization
and privileges. JAAS implements a standard pluggable authentication
module (PAM) in Java that extends Java?s security framework in order
to support user authorizations using standard authentication
providers such a LDAP, JNDI, or the operating system. Security is
discussed in detail in Chapter 12.
That?s a lot of information, but you will
run into these terms throughout the remainder of this book and need
to have a basic understanding of their meaning.
This is an excerpt from "Oracle
10g Application Server Administration Handbook" by Don Burleson
and John Garmany.