![]() ![]() ![]() ![]() ![]() ![]() |
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:
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.
To use the wlcompile
task with a split development directory in the MedRec application suite:
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 Java EE Web Service by Programming a JWS File. |
wlcompile
works, create a simple XML file to compile the Physician application. First move to the physicianEar
subdirectory in the MedRec project directory: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.
mybuild.xml
file in the physicianEar
directory: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. |
mybuild.xml
file by defining a project named tutorial
:<project name="tutorial" default="build">
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: <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).
mybuild.xml
file, add the following line to close the project:</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>
After you create the mybuild.xml
file, you can use it to compile the application.
prompt> c:\bea\user_projects\domains\MedRecDomain\bin\setDomainEnv.cmd
physicianEar
directory and compile by running the mybuild.xml
script using the ant
command: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 10.0 SP0 Mon Mar 26 02:02:31 BST 2007 914577
[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: 22 seconds
prompt> ant -f wlcompile_tutorial.xml
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
04/05/2007 11:25 AM <DIR> .
04/05/2007 11:25 AM <DIR> ..
04/05/2007 11:25 AM 2,295 ejb-jar.xml
04/05/2007 11:25 AM 1,038 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
04/05/2007 11:22 AM <DIR> .
04/05/2007 11:22 AM <DIR> ..
04/05/2007 11:25 AM 686 PhysicianSession.class
04/05/2007 11:25 AM 3,014 PhysicianSession.java
04/05/2007 11:25 AM 7,081 PhysicianSessionEJB.class
04/05/2007 11:25 AM 10,724 PhysicianSessionEJB.java
04/05/2007 11:25 AM 277 PhysicianSessionHome.class
04/05/2007 11:25 AM 995 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
04/05/2007 11:22 AM <DIR> .
04/05/2007 11:22 AM <DIR> ..
04/05/2007 11:22 AM <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.
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.
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.
![]() ![]() ![]() |