Hi, Attached are two task definitions and a small set of patches to allow you to use ant to build weblogic EJBs. I developed these tasks for building EJBs here at Cortex and Cortex have agreed to let me give them to the ant project.
The new code consists of two optional ant tasks: ddcreator and ejbc.
ddcreator takes a set of deployment descriptor definitions according to the
weblogic definition language and generates the serialised deployment
descriptors, while ejbc takes the serialised deployment descriptor and
generates the various EJB support files required by Weblogic, including the
RMI stubs and skeletons. Both tasks only generate a result if it is out of
date with respect to the source.
Example usage of the ddcreator task would be
<ddcreator descriptors="${dd.dir}" dest="${gen.classes}"
classpath="${descriptorbuild.classpath}">
<include name="*.txt" />
</ddcreator>
where
descriptors is the directory where the text descriptor defintions are
located
dest is the directory where the serialised deployment descriptors are
written
classpath should include the weblogic tools and the classes containing the
home and remote interfaces for the various EJBs
The ejbc task is a little more complicated.
<ejbc descriptors="${gen.classes}" src="${src.dir}"
dest="${gen.classes}"
manifest="${build.manifest}"
classpath="${descriptorbuild.classpath}">
<include name="*.ser" />
</ejbc>
where
descriptors in this case is the directory where the serialised deployment
descriptors are located
src is the directory containing the source defining the home and remote
interfaces
dest is the directory where the generated support classes are written
manifest is a generated jar manifest file defining all of the EJBs to be
included
classpath should again contains the weblogic tools plus the home, remote and
bean classes.
Both tasks are MatchingTasks and the include element is generally used to
select the appropriate files.
The implementation of these tasks supports the way we have been building
EJBs at Cortex. In particular I set the ejbc options to those we currently
use. If it doesn't fit with other organisations, let me know. Also this is
geared to WebLogic 4.5. I have not yet looked at 5.1.
The implementation details of the two tasks are worth looking at a little
bit more closely. Both tasks are implemented as an ant task with a separate
helper class which is executed in a separate JVM. This is done because I
wanted to control the classpath under which the weblogic tools were
executed. The weblogic tools generally require the classpath to include the
class files for the home and remote interfaces of the beans you are
developing. I did not want to have to startup ant with its classpath
including the project it is compiling. Thus the ant tasks simply delegate
all the work to the helper in a separate JVM.
To create that JVM and have its output pumped into the project log, I used a
Java task object. I needed to modify the ant Task object, however, to make
the setProject method public so I could connect the project to the Java
task. I also added a validateDirectory method which allows any task to
validate that a given File object represents a directory and that the
directory exists. This could probably be used by a few other tasks.
Let me know what you think, especially if you are using WebLogic.
Cheers
Conor
--
Conor MacNeill
[EMAIL PROTECTED]
Cortex ebusiness Pty Limited
? src/main/org/apache/tools/ant/taskdefs/optional/DDCreator.java
? src/main/org/apache/tools/ant/taskdefs/optional/DDCreatorHelper.java
? src/main/org/apache/tools/ant/taskdefs/optional/ejbc.java
? src/main/org/apache/tools/ant/taskdefs/optional/ejbcHelper.java
Index: build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-ant/build.xml,v
retrieving revision 1.21
diff -u -r1.21 build.xml
--- build.xml 2000/04/27 19:52:52 1.21
+++ build.xml 2000/05/07 12:04:01
@@ -37,6 +37,8 @@
<target name="check_for_optional_packages">
<available property="bsf.present" classname="com.ibm.bsf.BSFManager" />
<available property="netrexx.present" classname="netrexx.lang.Rexx" />
+ <available property="ejbc.present" classname="weblogic.ejbc" />
+ <available property="DDCreator.present"
classname="weblogic.ejb.utils.DDCreator" />
</target>
<!-- =================================================================== -->
@@ -60,6 +62,8 @@
optimize="on" >
<exclude name="**/Script.java" unless="bsf.present" />
<exclude name="**/NetRexxC.java" unless="netrexx.present" />
+ <exclude name="**/EJBC*.java" unless="ejbc.present" />
+ <exclude name="**/DDCreator*.java" unless="DDCreator.present" />
</javac>
<copydir src="${src.dir}" dest="${build.classes}">
Index: src/main/org/apache/tools/ant/Task.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Task.java,v
retrieving revision 1.5
diff -u -r1.5 Task.java
--- src/main/org/apache/tools/ant/Task.java 2000/04/26 19:09:17 1.5
+++ src/main/org/apache/tools/ant/Task.java 2000/05/07 12:04:02
@@ -54,6 +54,8 @@
package org.apache.tools.ant;
+import java.io.File;
+
/**
* Base class for all tasks.
*/
@@ -73,7 +75,7 @@
*
* @param project Project in whose scope this task belongs.
*/
- void setProject(Project project) {
+ public void setProject(Project project) {
this.project = project;
}
@@ -124,5 +126,27 @@
public void setLocation(Location location) {
this.location = location;
}
+
+ /**
+ * Validate that a given directory exists and is in fact a directory.
+ *
+ * If the directory does not exists or is not a directory, a build
exception
+ * is thrown.
+ *
+ * @param dir the directory to be validated
+ * @param usage indicates the role the directory is being used for
(source, dest, etc)
+ *
+ * @throws BuildException if the given directory is not valid.
+ */
+ protected void validateDirectory(File dir, String usage) {
+ if (!dir.exists()) {
+ throw new BuildException("The " + usage + " directory, " +
dir.getName() + ", does not exist.");
+ }
+
+ if (!dir.isDirectory()) {
+ throw new BuildException("The " + usage + " directory, " +
dir.getName() + ", is not a directory");
+ }
+ }
+
}
Index: src/main/org/apache/tools/ant/taskdefs/defaults.properties
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
retrieving revision 1.10
diff -u -r1.10 defaults.properties
--- src/main/org/apache/tools/ant/taskdefs/defaults.properties 2000/03/23
03:40:32 1.10
+++ src/main/org/apache/tools/ant/taskdefs/defaults.properties 2000/05/07
12:04:03
@@ -32,6 +32,8 @@
script=org.apache.tools.ant.taskdefs.optional.Script
netrexxc=org.apache.tools.ant.taskdefs.optional.NetRexxC
renameext=org.apache.tools.ant.taskdefs.optional.RenameExtensions
+ejbc=org.apache.tools.ant.taskdefs.optional.ejbc
+ddcreator=org.apache.tools.ant.taskdefs.optional.DDCreator
# deprecated ant tasks (kept for back compatibility)
javadoc2=org.apache.tools.ant.taskdefs.Javadoc
ejbc.java
Description: Binary data
DDCreator.java
Description: Binary data
ejbcHelper.java
Description: Binary data
DDCreatorHelper.java
Description: Binary data
