Organization and Packaging

Prior to deployment to the J2EE server for execution, a J2EE application needs to be packaged. This is a means of combining the developed J2EE modules into a single file to be deployed. Depending on the type of application module, you can create different types of deployment files. Although each of these files is a JAR file (perhaps containing other JAR files), each one will belong to one of the following categories:

  • Client applications that use Java archive (JAR) files. JAR files are used to package a Java application together. They can contain Java classes or images. These types of files aren't directly deployed to a server. They're typically included in larger files.

  • Business components use EJB modules and are stored within JAR files. These are packaged with a larger archive called an EAR file.

  • Web modules use web archive (WAR) file. WAR files contain web components such as JSPs and Servlets. They can also include HTML and images. These are normally packaged within an EAR file.

  • Enterprise archive (EAR) files contain an entire J2EE application for deployment. They may contain client applications, web modules (packaged in a WAR file), or EJB components (packaged in a JAR file). When deploying applications, the EAR file is used for the deployment.

In the following sections, we go into greater detail explaining the structure of JAR, WAR, and EAR files.

Java Archive File

A JAR is a file that packages application files together (such as Java classes or images). It may be included within EAR and WAR files and within library paths. In addition to the application contents of a JAR file, it also contains a manifest file that keeps an inventory of the contents of the file. The contents of JAR files are compressed, which allows for faster downloads from web servers to clients. Additionally, JAR files can be cached on clients so they're only downloaded again if a newer version is found on the server.

Like all application archives (which are types of JARs), the JAR file's format is shown in Figure 9-2.

image from book
 myJAR.jar  ------- META-INF             ------- MANIFEST.MF  ------- img             ------- welcome.gif       ------- product.gif       ------- map.gif 
image from book

Figure 9-2: JAR file structure

Java Application Archive (JAR) Structure

The MANIFEST.MF in the META-INF acts as an inventory for what is stored in the JAR. In the preceding example, you're simply storing GIF files in an img subdirectory.

JAR files are managed via the jar command, with some similar syntax to the tar command. Syntax can be looked up with man jar . To create a simple JAR file containing image files, place them in a directory called img . Then do the following:

 $ jar -cvf icons.jar img/* added manifest adding: img/welcome.gif(in = 870) (out= 534)(deflated 38%) adding: img/product.gif(in = 871) (out= 542)(deflated 37%) ... $ ls -l total 1366 -rw-r--r--   1 oracle     dba       686829 May 10 13:11 icons.jar drwxr-xr-x   2 oracle     dba         2560 May 10 11:35 img 

To view the contents of the JAR file, use jar t filename , as follows :

 $ jar -tf icons.jar META-INF/ META-INF/MANIFEST.MF img/welcome.gif img/product.gif ... 

Notice the use of a manifest file within the JAR file. Also notice that during the creation of the JAR file, the contents were compressed.

Web Archive (WAR) File

Web application modules include JSPs and Servlets that generate dynamic presentation for the application. These components are packaged within a WAR file, which may contain JSPs, Servlets, HTML, and images.

WAR files use the structure shown in Figure 9-3.

image from book
 myWebModule.war  ------- WEB-INF             ------- web.xml       ------- orion-web.xml             ------- classes                       ------ servlet1.class            ------ servlet2.class            ------ servletN.class             ------- lib             ------- library jar files  ------- index.html  ------- page1.jsp  ------- page2.jsp  ------- images             ------- welcome.gif       ------- product.gif       ------- map.gif 
image from book

Figure 9-3: WAR file structure

Web Application Archive (WAR) Structure

In the previous example, the WAR contains Servlets ( Servlet classes), JSPs ( pageN.jsp ), HTML ( index.html ), and image files (GIFs). These are located in the root directory.

Under the WEB-INF directory is the web.xml file. This file is the deployment descriptor for WAR files. It tells what parameters are to be used for the deployment and application.

A web.xml for the Petstore sample application is shown here:

 <?xml version="1.0" encoding="ISO-8859-1"?> <!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>   <display-name>WebTier</display-name>   <description>Web Tier DD for the PetStore application</description>   <servlet>     <servlet-name>webTierEntryPoint</servlet-name>     <display-name>centralServlet</display-name>     <description>no description</description>     <servlet-class>com.sun.j2ee.blueprints.petstore.control.web.MainServlet </servlet-class>   </servlet>   <servlet-mapping>     <servlet-name>webTierEntryPoint</servlet-name>     <url-pattern>/control/*</url-pattern>   </servlet-mapping>   <servlet>     <servlet-name>populateServlet</servlet-name>     <display-name>Populate Servlet</display-name>     <description>no description</description>     <servlet-class>com.sun.j2ee.blueprints.tools.populate.web.PopulateServlet </servlet-class>   </servlet>   <servlet-mapping>     <servlet-name>populateServlet</servlet-name>     <url-pattern>/populate</url-pattern>   </servlet-mapping>   <session-config>     <session-timeout>54</session-timeout>   </session-config>   <welcome-file-list>     <welcome-file>index.html</welcome-file>   </welcome-file-list>   <resource-ref>     <res-ref-name>jdbc/EstoreDataSource</res-ref-name>     <res-type>javax.sql.DataSource</res-type>     <res-auth>Container</res-auth>   </resource-ref>   <env-entry>     <env-entry-name>ejb/catalog/CatalogDAOClass</env-entry-name>     <env-entry-type>java.lang.String</env-entry-type>     <env-entry- value>com.sun.j2ee.blueprints.shoppingcart.catalog.dao.CatalogDAOImpl </env-entry-value>   </env-entry>   <env-entry>     <env-entry-name>ejb/profilemgr/ProfileMgrDAOClass</env-entry-name>     <env-entry-type>java.lang.String</env-entry-type>     <env-entry- value>com.sun.j2ee.blueprints.personalization.profilemgr.dao.ProfileMgrDAOImpl </env-entry-value>   </env-entry>   <env-entry>     <env-entry-name>server/ServerType</env-entry-name>     <env-entry-value>Oracle9iAS (1.0.2.2) Containers for J2EE</env-entry-value>     <env-entry-type>java.lang.String</env-entry-type>   </env-entry>   <ejb-ref>     <ejb-ref-name>ejb/catalog/Catalog</ejb-ref-name>     <ejb-ref-type>Session</ejb-ref-type>     <home>com.sun.j2ee.blueprints.shoppingcart.catalog.ejb.CatalogHome</home>     <remote>com.sun.j2ee.blueprints.shoppingcart.catalog.ejb.Catalog</remote>   </ejb-ref>   <ejb-ref>     <ejb-ref-name>ejb/cart/Cart</ejb-ref-name>     <ejb-ref-type>Session</ejb-ref-type>     <home>com.sun.j2ee.blueprints.shoppingcart.cart.ejb.ShoppingCartHome</home>     <remote>com.sun.j2ee.blueprints.shoppingcart.cart.ejb.ShoppingCart</remote>   </ejb-ref>   <ejb-ref>     <ejb-ref-name>ejb/customer/Customer</ejb-ref-name>     <ejb-ref-type>Session</ejb-ref-type>     <home>com.sun.j2ee.blueprints.customer.customer.ejb.CustomerHome</home>     <remote>com.sun.j2ee.blueprints.customer.customer.ejb.Customer</remote>   </ejb-ref>   <ejb-ref>     <ejb-ref-name>ejb/profilemgr/ProfileMgr</ejb-ref-name>     <ejb-ref-type>Entity</ejb-ref-type>     <home>com.sun.j2ee.blueprints.personalization.profilemgr.ejb.ProfileMgrHome </home>     <remote>com.sun.j2ee.blueprints.personalization.profilemgr.ejb.ProfileMgr </remote>   </ejb-ref>   <ejb-ref>     <ejb-ref-name>ejb/scc/Scc</ejb-ref-name>     <ejb-ref-type>Session</ejb-ref-type>     <home>com.sun.j2ee.blueprints.petstore.control.ejb.ShoppingClientControllerHome </home>     <remote>com.sun.j2ee.blueprints.petstore.control.ejb.ShoppingClientController </remote>   </ejb-ref>   <ejb-ref>     <ejb-ref-name>ejb/inventory/Inventory</ejb-ref-name>     <ejb-ref-type>Entity</ejb-ref-type>     <home>com.sun.j2ee.blueprints.inventory.ejb.InventoryHome</home>     <remote>com.sun.j2ee.blueprints.inventory.ejb.Inventory</remote>   </ejb-ref> </web-app> 

Here you can see Servlet and EJB mappings within the web.xml file.

Within the WEB-INF directory are also subdirectories for classes and library JAR files, as shown here:

 $ ls lib classes classes: com  javax  META-INF  org lib: customerEjb_client.jar   jaxp.jar parser.jar               shoppingcartEjb_client.jar inventoryEjb_client.jar  mailerEjb_client.jar personalizationEjb_client.jar     signonEjb_client.jar $ 

The web module files (JSPs and HTML) can be found in $ORACLE_HOME/j2ee/home/applications/petstore/petstore , as follows:

 $ ls -altr *jsp -rw-r--r--    1 oracle   dba          1429 May 27 21:01 topindex.jsp -rw-r--r--    1 oracle   dba          1101 May 27 21:01 template.jsp -rw-r--r--    1 oracle   dba           863 May 27 21:01 splash.jsp -rw-r--r--    1 oracle   dba           347 May 27 21:01 signoff.jsp -rw-r--r--    1 oracle   dba           360 May 27 21:01 signinsuccess.jsp -rw-r--r--    1 oracle   dba          1391 May 27 21:01 signin.jsp -rw-r--r--    1 oracle   dba          1557 May 27 21:01 sideindex.jsp $ ls -altr *html -rw-r--r--    1 oracle   dba          1480 May 27 21:01 preferencesform.html -rw-r--r--    1 oracle   dba          2444 May 27 21:01 index.html -rw-r--r--    1 oracle   dba           262 May 27 21:01 annotated-index.html -rw-r--r--    1 oracle   dba          1973 May 27 21:01 addressform.html $ ls -l META-INF total 4 -rw-r--r--    1 oracle   dba            23 May 27 21:01 MANIFEST.MF $ ls -l WEB-INF total 24 drwxr-xr-x    6 oracle   dba          4096 May 27 21:01 classes drwxr-xr-x    2 oracle   dba          4096 May 27 21:01 lib drwxr-xr-x    2 oracle   dba          4096 May 27 21:01 sql drwxr-xr-x    2 oracle   dba          4096 May 27 21:01 tlds -rw-r--r--    1 oracle   dba          3854 May 27 21:01 web.xml drwxr-xr-x    3 oracle   dba          4096 May 27 21:01 xml $ 

There's also an orion-web.xml file located in $ORACLE_HOME/j2ee/home/application-deployments/petstore/petstore . This file specifies OC4J options such as autoreloading and timeouts. The following is a sample orion-web.xml file:

 <?xml version="1.0"?> <!DOCTYPE orion-web-app PUBLIC "-//ORACLE//DTD OC4J Web Application 9.04//EN" "http://xmlns.oracle.com/ias/dtds/orion-web-9_04.dtd"> <orion-web-app         deployment-version="9.0.4.0.0"         jsp-cache-directory="./persistence"         temporary-directory="./temp" >         <!-- Uncomment this element to control web application class loader behavior.                 <web-app-class-loader search-local-classes-first="true" include-war-manifest-class-path="true" />         -->         <resource-ref-mapping name="jdbc/EstoreDataSource" />         <ejb-ref-mapping name="ejb/catalog/Catalog" />         <ejb-ref-mapping name="ejb/cart/Cart" />         <ejb-ref-mapping name="ejb/customer/Customer" />         <ejb-ref-mapping name="ejb/profilemgr/ProfileMgr" />         <ejb-ref-mapping name="ejb/scc/Scc" />         <ejb-ref-mapping name="ejb/inventory/Inventory" /> </orion-web-app> 

Because the Petstore application contains EJB components, there will also be orion-ejb-jar .xml files located within each *. jar directory in $ORACLE_HOME/j2ee/home/application-deployments/petstore .

These files are extracted from the WAR file during deployment. The WAR file is itself a web module contained within a larger deployment file called the enterprise archive (EAR) file.

Enterprise Archive (EAR) File

EAR files are a type of archive file designed to contain an entire J2EE application. The EAR file is what contains the modules that are composing a single application. It also represents what is actually deployed to the server. Packaging all the necessary modules together allows for easier deployment. The modules follow a standard structure that allows them to be deployed to any J2EE server. An EAR file is composed of the following:

  • XML configuration files (for examples, application.xml and orion-application.xml ).

  • Library components such as manifest files.

  • Web modules such as JSPs and Servlets with HTML and image files. These are stored in a web archive (WAR) file. These files optionally may be included depending on if the application uses web components.

  • Business modules such as EJBs stored in a Java archive (JAR) file. This optionally may be included depending on if the application uses EJBs.

  • Client modules that access remote applications. Inclusion is optional depending on if the application uses it.

  • Resource adapter that provides connection information to the EIS (database) tier.

EAR files use the structure shown in Figure 9-4.

image from book
 myApp.ear  ------- META-INF             ------- application.xml       ------- orion-application.xml  ------- myApp.jar  ------- myWebModule.war  ------- myEJB.jar 
image from book

Figure 9-4: EAR file structure

Enterprise Application Archive (EAR) Structure

In the preceding example you have an EAR ( myApp.ear ) file containing a JAR ( myApp.jar ); a web module ( myWebModule.war ) containing Servlets, JSPs, HTML, and images; and an EJB component ( myEJB.jar ). It's not required to include all these components, but they are included here.

Under the META-INF directory you have the application.xml . This deployment descriptor file identifies the components in the EAR file and their relative locations. The orion-application.xml deployment descriptor file specifies OC4J specific parameters.

A sample application.xml from the Petstore application is provided here:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN' 'http://java.sun.com/j2ee/dtds/application_1_2.dtd'> <application>   <display-name>petstore</display-name>   <description>Application description</description>   <module>     <ejb>petstoreEjb.jar</ejb>   </module>   <module>     <ejb>signonEjb.jar</ejb>   </module>   <module>     <web>       <web-uri>petstore.war</web-uri>       <context-root></context-root>     </web>   </module>   <module>     <ejb>customerEjb.jar</ejb>   </module>   <module>     <ejb>personalizationEjb.jar</ejb>   </module>   <module>     <ejb>inventoryEjb.jar</ejb>   </module>   <module>     <ejb>shoppingcartEjb.jar</ejb>   </module>   <module>     <ejb>mailerEjb.jar</ejb>   </module> </application> 

Here you can see that there are multiple modules within this application. It has seven EJB JAR files and one web module ( petstore.war ).

By packaging developed applications into EAR files (which may contain web applications, WAR and JAR files, and EJBs), a file that can be deployed to a J2EE server is created.



Oracle Application Server 10g. J2EE Deployment and Administration
Oracle Application Server 10g: J2EE Deployment and Administration
ISBN: 1590592352
EAN: 2147483647
Year: 2004
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net