Friday, July 8, 2011

WebLogic Server Application Packaging

Packaging Overview
WebLogic Server J2EE applications are packaged according to J2EE specifications. J2EE defines component behaviors and packaging in a generic, portable way, postponing run-time configuration until the component is actually deployed on an application server.
J2EE includes deployment specifications for Web applications, EJB modules, enterprise applications, client applications, and resource adapters. J2EE does not specify how an application is deployed on the target server—only how a standard component or application is packaged.
For each component type, the specifications define the files required and their location in the directory structure. Components and applications may include Java classes for EJBs and servlets, resource adapters, Web pages and supporting files, XML-formatted deployment descriptors, and JAR files containing other components.
An application that is ready to deploy on WebLogic Server may require WebLogic-specific deployment descriptors and, possibly, container classes generated with the WebLogic EJB, RMI, or JSP compilers.

JAR Files
A file created with the Java jar tool bundles the files in a directory into a single Java ARchive (JAR) file, maintaining the directory structure. The Java classloader can search for Java class files (and other file types) in a JAR file the same way that it searches a directory in its classpath. Because the classloader can search a directory or a JAR file, you can deploy J2EE components on WebLogic Server in either an "exploded" directory or a JAR file.
JAR files are convenient for packaging components and applications for distribution. They are easier to copy, they use up fewer file handles than an exploded directory, and they can save disk space with file compression. If your Administration Server manages a domain with multiple WebLogic Servers, you can only deploy JAR or EAR files, because the Administration Console does not copy expanded directories to Managed Servers.
The jar utility is in the bin directory of your Java Development Kit. If you have javac in your path, you also have jar in your path. The jar command syntax and behavior is similar to the UNIX tar command.
The most common usages of the jar command are:
jar cf jar-file files ...
Creates a JAR file named jar-file containing listed files. If you include a directory in the list of files, all files in that directory and its subdirectories are added to the JAR file.
jar xf jar-file
Extract (unbundle) a JAR file in the current directory.
jar tf jar-file
List (tell) the contents of a JAR file.
The first flag specifies the operation: create, extract, or list (tell). The f flag must be followed by a JAR file name. Without the f flag, jar reads or writes JAR file contents on stdin orstdout which is usually not what you want. See the documentation for the JDK utilities for more about jar command options
Packaging Resource Adapters ( RAR files )
To stage and package a resource adapter:
  1. Create a temporary staging directory anywhere on your hard drive.
  2. Compile or copy the resource adapter Java classes into the staging directory.
  3. Create a JAR to store the resource adapter Java classes. Add this JAR to the top level of the staging directory.
  4. Create a META-INF subdirectory in the staging directory.
  5. Create an ra.xml deployment descriptor in the META-INF subdirectory and add entries for the resource adapter.


  6. Create a weblogic-ra.xml deployment descriptor in the META-INF subdirectory and add entries for the resource adapter.

  7. When the resource adapter classes and deployment descriptors are set up in the staging directory, you can create the RAR with a JAR command such as:
    jar cvf jar-file.rar -C staging-dir
    This command creates a RAR that you can deploy on a WebLogic Server or package in an enterprise application archive (EAR).
    The -C staging-dir option instructs the JAR command to change to the staging-dir directory so that the directory paths recorded in the JAR are relative to the directory where you staged the resource adapters.


Packaging Enterprise Applications: Main Steps ( EAR Files )
To stage and package an Enterprise application:
  1. Create a temporary staging directory anywhere on your hard drive.
  2. Copy the Web archives (WAR files) and EJB archives (JAR files) into the staging directory.
  3. Create a META-INF subdirectory in the staging directory.
  4. Set up your shell environment.
    On Windows NT, execute the setenv.cmd command, located in the directory server\bin\setenv.cmd, where server is the top-level directory in which WebLogic Server is installed.
    On UNIX, execute the setenv.sh command, located in the directory server/bin/setenv.sh, where server is the directory in which WebLogic Server is installed.

  5. Execute the following command to automatically generate the application.xml deployment descriptor in the META-INF subdirectory:
    java weblogic.ant.taskdefs.ear.DDInit staging-dir
    where staging-dir refers to the staging directory.
    Alternatively, you can create the application.xml file automatically in the META-INF directory. 

  6. Optionally create the weblogic-application.xml file manually in the META-INF directory.

  7. Create the Enterprise Archive (EAR file) for the application, using a jar command such as:
    jar cvf application.ear -C staging-dir
    The resulting EAR file can be deployed using the Administration Console or the weblogic.Deployer command-line utility.


Staging and Packaging EJBs ( JAR files )
To stage and package an Enterprise JavaBean (EJB):
  1. Create a temporary staging directory anywhere on your hard drive (for example, c:\stagedir).
  2. Compile or copy the bean's Java classes into the staging directory.
  3. Create a META-INF subdirectory in the staging directory.
  4. Set up your shell environment.
    On Windows NT, execute the setenv.cmd command, located in the directory server\bin\setenv.cmd, where server is the top-level directory in which WebLogic Server is installed.
    On UNIX, execute the setenv.sh command, located in the directory server/bin/setenv.sh, where server is the top-level directory in which WebLogic Server is installed and domain refers to the name of your domain.

  5. If you are using EJB 1.1, e the following command to automatically generate the ejb-jar.xmlweblogic-ejb-jar.xml, and weblogic-rdbms-cmp-jar-bean_name.xml (if needed) deployment descriptors in the META-INF subdirectory:
    java weblogic.ant.taskdefs.ejb11.DDInit staging-dir
    where staging-dir refers to the staging directory. Use this utility for EJB 1.1.
    If you are creating EJB 2.0, execute:
    java weblogic.ant.taskdefs.ejb20.DDInit staging-dir
    Alternatively, you can create the EJB deployment descriptor files manually. Create an ejb-jar.xml and weblogic-ejb-jar.xml files in the META-INF subdirectory. If the bean is an entity bean with container-managed persistence, create a weblogic-rdbms-cmp-jar—bean_name.xml deployment descriptor in the META-INF directory with entries for the bean. Map the bean to this CMP deployment descriptor with a <type-storage> attribute in the weblogic-ejb-jar.xml file.

    When all of the enterprise bean classes and deployment descriptors are set up in the staging directory, create the EJB JAR file with a jar command such as:
    jar cvf jar-file.jar -C staging-dir
    This command creates a JAR file that you can deploy on WebLogic Server.
    The -C staging-dir option instructs the jar command to change to the staging-dir directory so that the directory paths recorded in the JAR file are relative to the directory where you staged the enterprise beans.
    Enterprise beans require container classes, classes the WebLogic EJB compiler generates to allow the bean to deploy in a WebLogic Server. The WebLogic EJB compiler reads the deployment descriptors in the EJB JAR file to determine how to generate the classes. You can run the WebLogic EJB compiler on the JAR file before you deploy the beans, or you can let WebLogic Server run the compiler for you at deployment time. 



Packaging Web Applications ( WAR files )
To stage and package a Web application:
  1. Create a temporary staging directory anywhere on your hard drive. You can name this directory anything you want.
  2. Copy all of your HTML files, JSP files, images, and any other files that these Web pages reference into the staging directory, maintaining the directory structure for referenced files. For example, if an HTML file has a tag such as <img src="images/pic.gif">, the pic.gif file must be in the images subdirectory beneath the HTML file.
  3. Create META-INF and WEB-INF/classes subdirectories in the staging directory to hold deployment descriptors and compiled Java classes.
  4. Copy or compile any servlet classes and helper classes into the WEB-INF/classes subdirectory.
  5. Copy the home and remote interface classes for enterprise beans used by the servlets into the WEB-INF/classes subdirectory.
  6. Copy JSP tag libraries into the WEB-INF subdirectory. (Tag libraries may be installed in a subdirectory beneath WEB-INF; the path to the .tld file is coded in the .jsp file.)
  7. Set up your shell environment.
    On Windows NT, execute the setenv.cmd command, located in the directory server\bin\setenv.cmd, where server is the top-level directory in which WebLogic Server is installed.
    On UNIX, execute the setenv.sh command, located in the directory server/bin/setenv.sh, where server is the top-level directory in which WebLogic Server is installed.

  8. Execute the following command to automatically generate the web.xml and weblogic.xml deployment descriptors in the WEB-INF subdirectory:
    java weblogic.ant.taskdefs.war.DDInit staging-dir
    where staging-dir refers to the staging directory.

    Alternatively, you can create the web.xml and weblogic.xml files manually in the WEB-INF subdirectory manually

    Bundle the staging directory into a WAR file by executing a jar command such as:
    jar cvf myapp.war -C staging-dir
    The resulting WAR file can be added to an Enterprise application (EAR file) or deployed independently using the Administration Console or the weblogic.Deployercommand-line utility.





5 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete