![]() |
![]() |
Building the MedRec Applications
Tutorial 7: Compiling Applications Using the Split Development Directory
This tutorial explains how to compile Enterprise Application source files using 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:
|
Procedure
Follow these steps 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.
cd c:\medrec_tutorial\src\physicianEar
notepad mybuild.xml
Note: If you do not want to enter the build.xml file manually, copy the file wlcompile_tutorial.xml file to the new file name, mybuild.xml. Then follow along to understand the file contents.
<project name="tutorial" default="build">
<target name="build">
<wlcompile srcdir="c:/medrec_tutorial/src/physicianEar" destdir="c:/medrec_tutorial/build/physicianEar"/>
</target>
</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"/>
</target>
</project>
Step 2: Compile the application.
After you create the mybuild.xml file, you can use it to compile the application.
c:\bea\user_projects\domains\MedRecDomain\setEnv.cmd
cd c:\medrec_tutorial\src\physicianEar
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
mybuild:
[javadoc] Generating Javadoc
[javadoc] Javadoc execution
[javadoc] Loading source file C:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\m edrec\controller\PhysicianSessionEJB.java...
[javadoc] Constructing Javadoc information...
[javadoc] EJBGen 2.13beta
[javadoc] Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\m edrec\controller\PhysicianSessionHome.java
[javadoc] Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\m edrec\controller\PhysicianSession.java
[javadoc] Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\ejb-jar.x ml
[javadoc] Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\weblogic- ejb-jar.xml
[javadoc] Creating C:\medrec_tutorial\build\physicianEar\physSessionEjbs\ejbgen-bu ild.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
[javac] Compiling 13 source files to C:\medrec_tutorial\build\physicianEar\physicianWebApp\WEB-INF\c lasses
BUILD SUCCESSFUL
Total time: 4 seconds
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 EJBs. Verify that the deployment descriptors were created:
dir c:\medrec_tutorial\build\physicianEar\physSessionEjbs\META-INF
Directory of c:\medrec_tutorial\build\physicianEar\physSessionEjbs\META-INF
02/21/2003 05:32p <DIR> .
02/21/2003 05:32p <DIR> ..
02/21/2003 05:32p 697 ejb-jar.xml
02/21/2003 05:32p 884 weblogic-ejb-jar.xml
wlcompile also compiled the and copied the actual EJB classes to the physSessionEjbs directory:
dir c:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\med rec\controller
Directory of c:\medrec_tutorial\build\physicianEar\physSessionEjbs\com\bea\med rec\controller
02/21/2003 05:32p <DIR> .
02/21/2003 05:32p <DIR> ..
02/21/2003 05:32p 11,359 PhysicianClientUtils.class
02/21/2003 05:32p 681 PhysicianSession.class
02/21/2003 05:32p 2,212 PhysicianSession.java
02/21/2003 05:32p 5,770 PhysicianSessionEJB.class
02/21/2003 05:32p 8,710 PhysicianSessionEJB.java
02/21/2003 05:32p 324 PhysicianSessionHome.class
02/21/2003 05:32p 428 PhysicianSessionHome.java
7 File(s) 29,484 bytes
wlcompile compiled the Web Application servlet classes and placed them in the WEB-INF\classes directory:
dir c:\medrec_tutorial\build\physicianEar\physicianWebApp\WEB-INF\cla sses\com\bea\medrec
Directory of c:\medrec_tutorial\build\physicianEar\physicianWebApp\WEB-INF\cla sses\com\bea\medrec
02/24/2003 10:53a <DIR> .
02/24/2003 10:53a <DIR> ..
02/24/2003 10:53a <DIR> actions
02/24/2003 10:53a <DIR> utils
The actions directory stores struts action classes and the utils directory contains a utility class that stores MedRec constants.
Notice that the entire build directory for the Enterprise Application (c:\medrec_tutorial\build\physicianEar) contains deployment descriptor files only for the EJB components. This is because the EJB descriptors are generated using ejbgen tags. You can recreate the entire contents of the build directory, including the EJB deployment descriptors, by rerunning the build script.
The Enterprise Application and Web Application deployment descriptors 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 this excerpt from the medrecEar\build.xml file:
<wlcompile srcdir="${medrec.ear.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 medrecEar source directory.
The build then continues by compiling only the xml and webServicesEjb modules in the application:
<wlcompile srcdir="${medrec.ear.src.dir}" destdir="${dest.dir}"
includes="xml, webServicesEjb"
|
Related Reading
![]() |
![]() |
![]() |