You are on page 1of 6

Introduction to Java Applications:

Java:
J2SE: Java 2 Platform, Standard Edition.
Java API, JDBC, Swing etc.,
J2EE: Java 2 Platform, Enterprise Edition.
Servlets, JSP, EJB etc.,
J2ME: Java 2 Platform, Micro Edition.
Designed for embedded systems, mobile Devices, Card Technology.

Web Application:
A Web Application always includes the following files:
 A servlet or JSP page, along with any helper classes.
 A web.xml deployment descriptor, a J2EE standard XML document that
configures the contents of a WAR file.
Web Applications may also contain JSP tag libraries, static .html and image files,
supporting classes and .jar files, and an ibm-web.xml deployment descriptor,
which configures Web sphere Server-specific elements for Web Applications

Structure of WAR file:


You develop your Web Application within a specified directory structure so
that it can be archived and deployed on web sphere Server, or another J2EE
compliant server. All servlets, classes, static files, and other resources
belonging to a Web Application are organized under a directory hierarchy. The
root of this hierarchy defines the document root of your Web Application. All
files under this root directory can be served to the client, except for files under
the special directory WEB-INF, located under the root directory. The name of
your Web Application is used to resolve requests for components of the Web
Application.
Place private files in the WEB-INF directory, under the root directory. All
files under WEB-INF are private, and are not served to a client.
WebApplicationName/
Place your static files, such as HTML files and JSP files in this directory (or a
subdirectory). This directory is the document root of your Web Application.

/WEB-INF/web.xml
The Web Application deployment descriptor that configures the Web
Application.

/src
Contains server-side java source code such as HTTP servlets and utility
classes.

/classes
Contains server-side classes such as HTTP servlets and utility classes.

/WEB-INF/lib
Contains .jar files used by the Web Application, including JSP tag libraries.
Below figure shows the basic structure of a Web application:
EJB Applications:
Enterprise JavaBeans (EJBs) are reusable Java components that implement
business logic and enable you to develop component-based distributed business
applications. EJB modules are packaged as archive files having a .jar extension,
but are generally deployed as exploded archive directories. The archive file or
exploded archive directory for an EJB contains the compiled EJB classes, optional
generated classes, and XML deployment descriptors for the EJB.
All EJB’s must be packed ( or exploded ) in a file called as JAR file ( Java Archive)
and the structure of JAR is as follows:

Enterprise Application:
An Enterprise Application consists of one or more of the following J2EE
applications or modules:
Web Applications
Enterprise Java Beans (EJB) modules
Resource Adapter modules
An Enterprise Application is packaged as a JAR file with an .ear extension,
but is generally deployed as an exploded EAR directory. An exploded EAR
directory contains all of the JAR, WAR, and RAR modules (also in exploded format)
for an application as well as the XML descriptor files for the Enterprise Application
and its bundled applications and modules.

XML Deployment Descriptors:

A key file that defines each type of deployment unit is its XML deployment
descriptor. The deployment descriptor is an XML document that defines certain
runtime characteristics for the application or module.

APPLICATION PLATFORM DESCRIPTOR FILE


Web Application [.war] Java Web.xml

Ejb Application [.jar] Java ejb-jar.xml

Enterprise Application [.ear] Java Application.xml


Sample DD(Deployment Descriptors):

Sample Web.xml: (for web application .war file)


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-
app_2_2.dtd">

<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>mypackage.HelloServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
</web-app>

Sample Ejb-jar.xml: (for ejb application .jar file)

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD
Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-
jar_2_0.dtd'>

<ejb-jar>
<enterprise-beans>
<message-driven>
<ejb-name>MessageBean</ejb-name>
<ejb-class>samples.mdb.ejb.MessageBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
</message-driven-destination>
<resource-ref>
<res-ref-name>jms/QueueConnFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>MessageBean</ejb-name>
<method-intf>Bean</method-intf>
<method-name>onMessage</method-name>
<method-params>
<method-param>javax.jms.Message</method-param>
</method-params>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

Sample application.xml: (for enterprise application .ear file)

<?xml version="1.0" encoding="UTF-8"?>


<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/application_5.xsd">

<application>
<module>
<java>test-client.jar</java>
</module>

<module>
<ejb>test-ejb.jar</ejb>
</module>

<module>
<web>
<web-uri>test.war</web-uri>
<context-root>test</context-root>
</web>
</module>

<library-directory>lib</library-directory>
</application>

You might also like