Hello World Split Development Directory EAR

This example illustrates how to use the WebLogic split development directory structure and associated Ant tasks to build, package, and deploy Enterprise Applications.

See:
          Description

  Packages

examples.splitdir.hello  
examples.splitdir.hello.apputils  
examples.splitdir.hello.startup  
examples.splitdir.hello.webutils  

 

This example illustrates how to use the WebLogic split development directory structure and associated Ant tasks to build, package, and deploy Enterprise Applications.

The example folder contains a subdirectory, helloWorldEar, that represents the project directory for the Enterprise Application. All subdirectories within helloWorldEar follow the split development directory structure for storing source files, and are described below.

 

  Additional Resources for examples.splitdir

./helloWorldEar/build.xml The Java Ant script that builds, packages, and deploys helloWorldEar and its components.
./helloWorldEar/APP-INF/classes/applicationresource.properties A properties file whose values are read by the application utility class. The contents are used to construct the "hello world" message.

 

The following sections describe how to build and run the example.

  1. Before You Build
  2. Build the Example
  3. Run the Example
  4. Troubleshoot Problems

 

Before You Build

The examples.splitdir.helloWorldEar example provides the source for a simple but complete Enterprise Application that conforms to the WebLogic split development directory structure. Because the example uses this directory structure, you can use WebLogic Ant tasks to easily compile, package, and deploy either the whole application or individual components of the application.

helloWorldEar is the main project directory that holds the entire source for the Enterprise Application. Examine the layout of directories and components in the helloWorldEar directory:

  • APP-INF/classes contains a properties file, applicationresource.properties, that is read by a utility class in the Enterprise Application. In your own applications, APP-INF/classes can store any resources that are shared by classes in the application.

  • APP-INF/lib contains a completed .jar file, GenericResourceLoader.jar. In your own applications, you can place any third-party utility .jars in APP-INF/lib. (The source for GenericResourceLoader.jar can be found in the examples/thirdparty directory.)

  • appStartup and appUtils contain the source for two classes. appStartup is a simple class that uses Application Lifecycle Events to initialize the applicationresources.properties file when you redeploy the application. It initializes the file using appUtils. appUtilsg is a utility class that uses GenericResourceLoader.jar to read the contents of the properties file. appUtils is called by an EJB to display the "hello" message. In both subdirectories, the .java source files are stored in subdirectories that reflect their package structures.

    In your own applications, source files for supporting and utility classes can be stored in any subdirectory of the Enterprise Application project directory; the wlcompile Ant tasks automatically compiles these classes into the APP-INF/classes directory of the final Enterprise Application, so they can be accessed by other components.

  • build.xml is the Ant build file used to build and deploy the sample application. When you store your own source files using the split development directory structure, you can use the weblogic.BuildXMLGen utility to automatically create the build.xml file for you, with common build targets.

    The installed build.xml file has several differences from a file generated by weblogic.BuildXMLGen:

    • It uses the properties file installed with the WebLogic Server Examples to use common directories.
    • It uses the exclude option to wlcompile to control the order in which components are compiled.

    You can examine these differences by generating a separate build.xml file with weblogic.BuildXMLGen in a separate directory. However, the instructions that follow assume you are using the installed file.

  • helloEJB contains the source for an EJB used in the Enterprise Application. This EJB calls the appUtils class to display the "hello" message. Notice that this directory only contains the EJB source file stored in its package subdirectory. The deployment descriptor files for the EJB are generated automatically using ejbgen tags embedded in the source. The wlcompile task automatically runs ejbgen for EJB source files that use a .ejb extension.

  • helloWebApp contains .jsp and .java source files for the Web Application component of the Enterprise Applications. JSPs and static files can be stored in the top-level of a Web Application subdirectory. Servlets and supporting .java files should be stored in the WEB-INF/src subdirectory in subdirectories that reflect the class package. (The .java file in this example is not a Servlet, but a utility class used only by the JSP in this Web Application.)

    helloWebApp/WEB-INF also contains the deployment descriptors for the Web Application.

  • META-INF contains the deployment descriptor files for the Enterprise Application.

To get the most out of this example, examine the layout of subdirectories and use the same directory structure for your own Enterprise Applications. Doing so allows you to maintain source and editable files completely separate from compiled and generated files, and also enables you to use the WebLogic Ant tasks to easily perform repeated builds and deployments.

 

Build the Example

To build the example, follow these steps:
  1. Start the Examples Server.

  2. Open a new command shell and set your environment using the setExamplesEnv.cmd or setExamplesEnv.sh script.

  3. Move to the project directory where the build.xml script is located. For example:

    cd %EXAMPLES_HOME%\src\examples\splitdir\helloWorldEar

  4. Use the following command to display the available targets in build.xml

    ant

    These correspond to the default targets that would be generated in a build.xml file created by weblogic.BuildXMLGen. Targets are provided to build and deploy the entire Enterprise Application as well as individual components. There are also targets available to package the application as a .EAR file and undeploy or redeploy the application.

  5. To compile the application, enter the command:

    ant build

    This compiles all components of the application and places them in the build subdirectory of the samples home directory. If you examine the contents of this directory, you'll see that it contains only compiled classes and generated deployment descriptors. All of the source files and editable deployment descriptors remain in the original project directory. This is one of the key benefits of using the WebLogic split development directory - you don't have to stage or package the application before deploying it to the server. WebLogic Server can deploy the build directory by locating the necessary editable descriptor files in the source directory, as you'll see in the next step.

  6. Now that you've built the application, use the deploy target to deploy it to the Examples server:

    ant deploy

    The deploy target uses the wldeploy Ant task to deploy the application from the deploy directory. Editable files required for deployment (the Enterprise Application and Web Application deployment descriptors) are obtained from the project directory by reading the .beabuild.txt file stored in the /build/helloWorldEar directory.

    The build directory contains no editable files, so it can be easily removed and replaced as you develop your applications.

    Note: To improve the performance of the build and deploy operations, you can combine both targets on a single command line:

    ant build deploy

  7. The build.xml file also contains a target you can use to package the application:

    ant ear

    This target starts by compiling the entire Enterprise Application using wlcompile. It then uses the wlpackage task to generates a standard .ear file, obtaining necessary files from both the build and project directories. You can find the complete .ear file in the %EXAMPLES_HOME%\build\dist directory.

 

Run the Example

After you have built and deployed the example, access the Web Application by pointing your browser to the URL:

http://www.setgetweb.com:7001/helloWebApp

This accesses the .jsp in the Enterprise Application's Web Application. The last line of the output is obtained by calling the Enterprise Application's EJB. The EJB obtains the information to print by accessing the utility class, which retrieves the text from the properties file.

You can change the last line of output by editing the properties file with a text editor. Simply change the value of hello.ejb.identity and redeploy the application. The appStartup class detects the deployment and loads the file, so that the new message is displayed when you next access the JSP. appStartup also logs a message in the server's log file in response to the deployment event; you can view these messages in the examples.log file in the Examples server root directory.

 

See Also

Read more about the WebLogic split development directory and Ant tasks at: