Avitek Medical Records Development Tutorials

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

 


Developing the MedRec Applications

 


Tutorial 7: Compiling Split Development Directory Applications with Ant Tasks

This tutorial explains how to compile Enterprise Application source files with the wlcompile Ant task. wlcompile works with a WebLogic split development directory structure to produce a build or output directory, which contains the compiled Java classes. The build directory and the source directory described in Tutorial 6: Understanding the WebLogic Server Split Directory Structure constitute a deployable application in WebLogic Server.

Later tutorials explain how to use other WebLogic Server Ant tasks that work with the split development directory to perform other application building tasks such as:

This tutorial includes the following sections:

 


Prerequisites

Before starting this tutorial:

As you may have noticed if you looked at the contents of the \build directory right after unpacking the medrec_tutorial.zip file, many classes that make up the MedRec application have already been built for you. This includes all the classes in the \medrecEar and \startBrowserEar applications, as well as the Web Services in the \physicianEar application. This tutorial describes how to compile the classes of the physicianEar application that have not been pre-compiled (EJBs and Web application-related) using the wlcompile Ant task. You can, of course, recompile any of the pre-built classes as well.

 


Procedure

To use the wlcompile task with a split development directory in the MedRec application suite:

Step 1: Create the build.xml file.

Storing your source files using the WebLogic split development directory structure simplifies the build.xml file required to compile your applications. For most Enterprise Applications, a simple script of several lines is adequate to compile all modules—the wlcompile task automatically determines the modules used in the application and maintains classpath dependencies accordingly.

Note: In this release of WebLogic Server, the wlcompile Ant task does not compile Web Services that have been implemented with Java Web Service (JWS) files. Rather, you must explicitly call the jwsc Web Service Ant task to generate the Web Service before calling the wlcompile task to compile all other components, such as EJBs. Additional details about jwsc are provided in Tutorial 11: Creating a J2EE Web Service by Programming a JWS File.
  1. To see how wlcompile works, create a simple XML file to compile the Physician application. First move to the physicianEar subdirectory in the MedRec project directory:
  2. prompt> cd c:\medrec_tutorial\src\physicianEar

    The top-level of physicianEar contains subdirectories for the Web Application, EJB, and Web Service components that form the Enterprise Application. You will store the XML file here as well.

  3. Use a text editor to create a new mybuild.xml file in the physicianEar directory:
  4. prompt> notepad mybuild.xml
    Note: If you do not want to enter the build.xml file manually, copy the file wlcompile_tutorial.xml file, located in the c:\medrec_tutorial\src\physicianEar directory, to the new file name, mybuild.xml. Then follow along to understand the file contents.
  5. Start the mybuild.xml file by defining a project named tutorial:
  6. <project name="tutorial" default="build">
  7. Define the main target for building the application. This target (named build) is fairly simple. It uses the wlcompile task to identify the source directory (which uses the split development directory structure) and an output directory for storing compiled files. Enter the following lines:
  8.   <target name="build">
    <wlcompile srcdir="c:/medrec_tutorial/src/physicianEar"
    destdir="c:/medrec_tutorial/build/physicianEar">
    <ejbgen source="1.5" />
    </wlcompile>
    </target>

    For most simple Enterprise Applications, you need only to point wlcompile to the source and build directories to use for compiling. Always make sure the srcdir and destdir directories point to separate locations—you want to ensure that your source and output files remain separate during the development process.

    The ejbgen Ant task specifies the version of the JDK that the EJBGen command should use when processing the *.ejb files. The EJBs in MedRec use the new JDK 5.0 metadata annotation feature, thus you should set the version attribute to 1.5 (which is the same as the 5.0 version of the JDK).

  9. To complete the mybuild.xml file, add the following line to close the project:
  10. </project>

    Your completed file should resemble the following. Remember that you can copy over wlcompile_tutorial.xml if you do not want to type in the full text:

    <project name="tutorial" default="build">

    <target name="build">
    <wlcompile srcdir="c:/medrec_tutorial/src/physicianEar"
    destdir="c:/medrec_tutorial/build/physicianEar">
    <ejbgen source="1.5" />
    </wlcompile>
    </target>

    </project>

Step 2: Compile the application.

After you create the mybuild.xml file, you can use it to compile the application.

  1. Make sure you have set your environment using the MedRecDomain environment script:
  2. prompt> c:\bea\user_projects\domains\MedRecDomain\bin\setDomainEnv.cmd
  3. Move to the physicianEar directory and compile by running the mybuild.xml script using the ant command:
  4. prompt> cd c:\medrec_tutorial\src\physicianEar
    prompt> ant -f mybuild.xml

    Although you did not add any informational messages to your build script, the wlcompile task produces its own output to show its progress:

    Buildfile: mybuild.xml
    build:
    [javac] Compiling 1 source file to C:\medrec_tutorial\build\physicianEar\APP-INF\classes
    [ejbgen] EJBGen WebLogic Server 9.2 SP0 Fri Jun 23 20:47:26 EDT 2006 783464
       [ejbgen]  Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\medrec\controller\PhysicianSessionHome.java
    [ejbgen] Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\medrec\controller\PhysicianSession.java
    [ejbgen] Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\\ejb-jar.xml
    [ejbgen] Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\\weblogic-ejb-jar.xml
    [move] Moving 2 files to C:\medrec_tutorial\build\physicianEar\physSessionEjbs\META-INF
    [javac] Compiling 3 source files to C:\medrec_tutorial\build\physicianEar\physSessionEjbs
    [wlcompile] Note: C:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\medrec\controller\PhysicianSessionEJB.java uses or overrides a deprecated API.
    [wlcompile] Note: Recompile with -Xlint:deprecation for details.
    [javac] Compiling 12 source files to C:\medrec_tutorial\build\physicianEar\physicianWebApp\WEB-INF\classes
    BUILD SUCCESSFUL
    Total time: 10 seconds
  5. If you did not receive the above output, or ran into a problem, you can use the Ant build file provided for this tutorial instead:
  6. prompt> ant -f wlcompile_tutorial.xml

Step 3: Examine the output files.

Now that you have compiled physicianEar, take a look at the build directory to see what happened. All output for the build target is placed in the output directory for the Enterprise Application, c:\medrec_tutorial\build\physicianEar.

The wlcompile output shows that the build started by running ejbgen on the Physician application's session EJBs. Verify that the deployment descriptors were created:

prompt> dir c:\medrec_tutorial\build\physicianEar\physSessionEjbs\META-INF
 Directory of c:\medrec_tutorial\build\physicianEar\physSessionEjbs\META-INF
07/24/2006  02:56 PM    <DIR>          .
07/24/2006 02:56 PM <DIR> ..
07/24/2006 02:56 PM 2,294 ejb-jar.xml
07/24/2006 02:56 PM 1,037 weblogic-ejb-jar.xml

The wlcompile Ant task also compiled the and copied the actual EJB classes to the physSessionEjbs directory:

prompt> dir c:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\medrec\controller

Directory of c:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\medrec\controller
07/24/2006  02:54 PM    <DIR>          .
07/24/2006 02:54 PM <DIR> ..
07/24/2006 02:56 PM 731 PhysicianSession.class
07/24/2006 02:56 PM 3,013 PhysicianSession.java
07/24/2006 02:56 PM 7,683 PhysicianSessionEJB.class
07/24/2006 02:56 PM 10,724 PhysicianSessionEJB.java
07/24/2006 02:56 PM 326 PhysicianSessionHome.class
07/24/2006 02:56 PM 994 PhysicianSessionHome.java

wlcompile compiled the Web Application servlet classes and placed them in the WEB-INF\classes directory:

prompt> dir c:\medrec_tutorial\build\physicianEar\physicianWebApp\WEB-INF\classes\com\bea\medrec
 Directory of c:\medrec_tutorial\build\physicianEar\physicianWebApp\WEB-INF\classes\com\bea\medrec
07/24/2006  02:54 PM    <DIR>          .
07/24/2006 02:54 PM <DIR> ..
07/24/2006 02:54 PM <DIR> actions

The actions directory stores struts action classes.

Notice that the entire build directory for the Enterprise Application (c:\medrec_tutorial\build\physicianEar) contains deployment descriptor files only for the EJB and Web Service components. This is because the EJB and Web Service descriptors are generated using ejbgen and Java Web Service (JWS) annotations, respectively. (The Web Services were pre-compiled as part of the .zip file). You can recreate the entire contents of the build directory, including the EJB and Web Services deployment descriptors, by rerunning the build script.

The Enterprise Application and Web Application deployment descriptors (application.xml, weblogic-application.xml, web.xml, and weblogic.xml) are left in the source directory because they are created and edited manually, and cannot be easily replaced or rebuilt.

 


Best Practices

More complex Enterprise Applications may have compilation dependencies that are not automatically handled by the wlcompile task. However, you can use the include and exclude options to wlcompile to enforce your own dependencies. include and exclude accept the names of Enterprise Application modules—the names of subdirectories in the Enterprise Application source directory—to include or exclude them from the compile stage. See The Big Picture for an example.

 


The Big Picture

Although the MedRec Enterprise Applications use the WebLogic split development directory structure and wlcompile task in their build scripts, they have certain dependencies that are not handled by the default wlcompile task. For example, examine the following sample excerpt from a build.xml file:

    <wlcompile srcdir="${src.dir}" destdir="${dest.dir}"
excludes="adminWebApp, xml, mdbEjbs, webServicesEjb"/>

You can see that the build script starts by compiling all modules in the Enterprise Application except for adminWebApp, xml, mdbEjbs, and webServicesEjb. These correspond to subdirectories names in the source directory.

The build might then continue by compiling only the xml and webServicesEjb modules in the application:

    <wlcompile srcdir="${src.dir}" destdir="${dest.dir}"
includes="xml, webServicesEjb"

It is also useful to note that, prior to compilation, the wlcompile Ant task adds the contents of both the source and the build/earName/APP-INF/lib and build/earName/APP-INF/classes to its CLASSPATH.

 


Related Reading


  Back to Top       Previous  Next