Packaging Your Application

The J2EE specification outlines numerous Java-based technologies. Table 15-1 lists some of the Java technologies supported by Oracle Application Server 10 g and the supported version of each of those technologies.

Table 15-1: Java Technologies Supported by Oracle Application Server 10g

Java Technology

Version of Specification Supported in Oracle Application Server 10 g

Java Server Pages (JSPs)

1.2

Servlets

2.3

Entity Java Beans (EJBs)

2.0

Java Message Service (JMS)

1.0.2b

Java Database Connectivity (JDBC)

2.0

Simple Object Access Protocol (SOAP)

1.1

Web Services Description Language (WSDL)

1.1

Universal Description, Discovery, and Integration (UDDI)

2.0

Since an application can be (and most likely will be) made up of a combination of these technologies, it would be helpful to have a standard way of organizing the various files that make up our applications so that when it came time to move these application components to an application server, the task could be handled in a standardized way. Luckily, the designers of the J2EE specification thought about this and have developed a standard that lists a set of directories for the components that make up your application. You can then group these files into an archive file using the jar (Java Archive) command. Depending on the complexity of your application, we may have JAR files that are made up of other JAR files. The different types of Java archive files are discussed in the next section. After the archive is created, it can be deployed to the application server container (OC4J) with ease.

The Directory Structure

The key to building an archive file to be deployed is maintaining your application files in a standard directory structure. Figure 15-1 lists the directory structure outlined by the J2EE specification.

A description of each level of the directory follows . Any directory name in <> is arbitrary; others are exact matches of what has to be in the directory structure (including case-sensitivity ):

click to expand
Figure 15-1: The directory structure outlined by the J2EE specification
Note  

The form <root> represents the root directory of your J2EE application; it is traditionally named after the application.

  • META-INF Location of the application.xml file that describes the modules in your J2EE application (see Chapter 2 for a detailed look at the application.xml file)

  • < ejb_module > Location of package(s) consisting of the EJB source code for the application; this directory is not mandatory and is omitted if your application does not make use of EJB technology

    • bmp Location of package(s) consisting of the source code of bean-managed persistent entity beans

    • cmp Location of package(s) consisting of the source code of container-managed persistent entity beans

  • META-INF Location of the ejb-jar.xml deployment descriptor file

  • < web module > Location of the web module, containing JSPs, JSP tag libraries, and HTML files

  • WEB-INF Location of the web.xml file

  • classes Starting location of the web module s/servlet classes

  • < package > Location of package(s) classes

  • lib dependent libraries

  • < client module > Location of client classes

  • META-INF Location of application-client .xml

Back in Chapter 2, we discussed the basic difference between EAR (Enterprise ARchive) and WAR (Web ARchive) files: an application that does not contain EJBs is considered a web application and is usually deployed as a WAR file. An application that contains EJBs is considered an EJB (or Enterprise) application and is deployed as an EAR file. Note that we said web applications are usually deployed as WAR files ”you could deploy a web application as an EAR file by leaving the directories for EJB modules empty. This is commonly referred to as wrapping a WAR file into an EAR file. If the application contains EJBs, however, it must be deployed as an EAR file. EAR files are further complicated by the fact that they contain WAR files ”the web- tier components of the application. The method of wrapping a WAR file into an EAR file is what Oracle does automatically when you click the Deploy WAR file button on the Applications page for the OC4J container.

Let s start with the simpler of the two and create a WAR file. Assuming you have created a directory structure similar to Figure 15-1 for your application development, you can create a WAR file by going into the <web module> directory under the <root> directory for your application. If, for example, you had created an application called hockeyapp, you might have a directory structure that looks like this:

 C:\ hockeyapp\          META-INF\                   application.xml          hockeyweb\                  Various HTML, JSP and image files                   WEB-INF\           web.xml                           classes\   Servlet classes                           lib\       Tag libraries 

Let s start with the first listing and build a WAR file from that. First cd to the <root>\<web module> directory ”in this example, it would be C:\hockeyapp\hockeyweb. From that directory, you can create a WAR file by typing

 jar cvf <name of war file> <directories to include in war file> 

So for this example, it would be

 jar cvf hockeyapp.war WEB-INF 

If your application contained EJBs, there would also be an EJB directory (hockey_ejb\ as an example):

 C:\ hockeyapp\        META-INF\                     application.xml        hockey_ejb\               META-INF\              ejb-jar.xml               hockey\                Various EJB interface .java files                  impl\              Various Bean implementation files        hockeyweb\                    Various HTML, JSP and image files        WEB-INF\                      web.xml               classes\               Servlet classes               lib\                   Tag libraries 

To create an EAR file from this directory, you need to perform a few more steps:

  1. Create a WAR file by cd ing to the <root>\<web module> directory (in this case, C:\hockeyapp\hockeyweb) and issuing the following command:

     jar cvf hockeyapp.war WEB-INF 
  2. Copy the newly created hockeyapp.war file up one level to the C:\hockeyapp directory.

  3. Next cd to the <ejb> directory (in this example, C:\hockeyapp\hockey_ejb).

  4. Create a jar file by issuing the following command:

     jar cvf <name of jar file> <directories to include in jar file> 

    For this example, it would be:

     jar cvf hockeyapp-ejb.jar META-INF hockey 
  5. Copy the newly created hockeyapp-ejb.jar file up one level to the C:\hockeyapp directory.

  6. Modify the application.xml file in the C:\hockeyapp\META-INF directory and add these two <module> sections:

     <?xml version="1.0"?> (!DOCTYPE application PUBLIC "-//Sun Microsystems,     Inc.//DTD J2EE Application 1.2//EN"    "http://java.sun.com/j2ee/dtds/application_1_2.dtd"> <! The application element is the root element of a     J2EE application deployment descriptor.    > <application>       <display-name>Hockey App</display-name>       <module>             <web>                   <web-uri>hockeyapp.war</web-uri>                   <context-root>/</context-root>             </web>       </module>       <module>             <ejb>hockeyapp-ejb.jar</ejb>       </module> </application> 
  7. Now cd back to the root directory of the application (in this example, C:\hockeyapp).

  8. Create the EAR file with the following command:

     jar cvf <name of ear file> <files/directories that will make up the ear file> 

    For our example, it would be:

     jar cvf hockeyapp.ear hockeyapp.war hockeyapp-ejb.jar META-INF 

Now that we have our EAR or WAR file, we can look at the next step we will need to perform before actually deploying our application to the application server.



Oracle Application Server 10g Web Development
Oracle Application Server 10g Web Development (Oracle Press)
ISBN: 0072255110
EAN: 2147483647
Year: 2004
Pages: 192

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