Sunday, 1 March 2009

J2EE Enterprise Archive (EAR), Web Application (WAR), WebServices (WAR) file structure:

J2EE Enterprise Archive (EAR), Web Application (WAR), WebServices (WAR) file structure:
--------------------------------------------------------------------
I will briefly explain here about J2EE applications file(EAR, WAR) structure to follow.

EAR (Enterprise Archive)File Structure

EAR_FILE_NAMe.ear
   WAR file(s) – web modules
   JAR file(s)—EJB modules
   RAR file(s)
   lib/
      JAR and ZIP files for shared libraries with in j2ee application
   META-INF/
      MANIFEST.MF
      application.xml (descriptor for j2ee web applications)

Here EAR (Enterprise Archive) can contain more than one Web modules (WAR files), More than EJB modules (JAR files).

Every Web module, EJB module details need to be entered in application.xml file under META-INF folder.

Example application.xml file format:
-----------------------------------
<?xml version="1.0" ?>
<application>
<display-name>J2EE Application</display-name>
<description>
sample J2EE application
</description>

<module>
<ejb>EJB_JAR_FILE_NAME.jar</ejb>
</module>

<module>
<web>
<web-uri>WAR_FILE_NAME.war</web-uri>
<context-root/MYURL</context-root>
</web>
</module>

<module>
<ava>CLIENT_JAR_FILE_NAME.jar</java>
</module>
</application>


WAR (Web Archive)file structure:

war_file_name.war
   html_folder(optional)
   js_folder(optional)
   JSP_folder(optional)
   Images_folder(optional)
   WEB-INF/ (must be there in War file)
      web.xml (standard J2EE Web descriptor file. This must be in war file)
      classes/
         common util, servlet classes,
      lib/
         JAR and ZIP files for shared libraries within web application

Here web application WAR file must contain WEB-INF folder and under that web.xml file must be included then only it is identified as web application by J2EE container.

WEB-INF can contain classes, lib folders. Java classes under lib folder (.class, or classes in jar, zip files) and classes folder are accessible within web application from anywhere like from jsp’s, servlets.

For modularity you can create/place html, js, images, jsp files under their respective folders. it is totally up to you to follow modularity.

Web.xml format:
----------------------
<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>web.xml file for Web Application</description>
<servlet>
<servlet-name>SearchServlet</servlet-name>
<servlet-class>com.yourcompany.module.ServletName</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>SearchServlet</servlet-name>
<url-pattern>/search</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>35</session-timeout>
</session-config>

<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>

<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>

</web-app>

Webservices Archive File Structure:

WebService_FILE_NAME.war
   WEB-INF/
      web.xml (standard J2EE Web descriptor file. Must be in war file)
      webservices.xml (J2EE descriptor)
      mapping_file.xml
      wsdl/
         wsdl_file.wsdl
      classes/
         class files
      lib/
         JAR and ZIP files for dependency classes

Please write back to me if you come up with more queries here.

In my next blog I will explain more about deploying EAR, WAR files on Oracle 10g application server OC4J container.

No comments:

Post a Comment