You can add support classes to all the generated jar fils by including a
<support-classes> nested element. This is effectively a fileset and
includes the ability to reference another fileset by refid
So
<ejbjar ...>
<support-classes dir="${build.classes.server}">
<include name="**/*.class"/>
</support-classes>
...
</ejbjar>
or
<ejbjar ...>
<support-classes refid="support.fileset"/>
...
</ejbjar>
Please note the following.
==========================
If your ejbjar task generates multiple jar files, the support classes will be
added to each one.
The nested element name may change. I am using it to test a facility I added
to the core. If it does change, it will change to <support>
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268486 13f79535-47bb-0310-9956-ffa450edef68
master
| @@ -69,8 +69,11 @@ public interface EJBDeploymentTool { | |||||
| * | * | ||||
| * @param descriptorFilename the name of the deployment descriptor | * @param descriptorFilename the name of the deployment descriptor | ||||
| * @param saxParser a SAX parser which can be used to parse the deployment descriptor. | * @param saxParser a SAX parser which can be used to parse the deployment descriptor. | ||||
| * @param supportFileSet a fileset containing all the files to be included in the | |||||
| * ` generated jarfile as support classes. | |||||
| */ | */ | ||||
| public void processDescriptor(String descriptorFilename, SAXParser saxParser) | |||||
| public void processDescriptor(String descriptorFilename, SAXParser saxParser, | |||||
| FileSet supportFileSet) | |||||
| throws BuildException; | throws BuildException; | ||||
| /** | /** | ||||
| @@ -137,6 +137,11 @@ public class EjbJar extends MatchingTask { | |||||
| */ | */ | ||||
| private ArrayList deploymentTools = new ArrayList(); | private ArrayList deploymentTools = new ArrayList(); | ||||
| /** | |||||
| * A Fileset of support classes | |||||
| */ | |||||
| private FileSet supportClasses = null; | |||||
| /** | /** | ||||
| * Create a weblogic nested element used to configure a | * Create a weblogic nested element used to configure a | ||||
| * deployment tool for Weblogic server. | * deployment tool for Weblogic server. | ||||
| @@ -178,6 +183,16 @@ public class EjbJar extends MatchingTask { | |||||
| return classpath.createPath(); | return classpath.createPath(); | ||||
| } | } | ||||
| public Object createElement(String elementName) { | |||||
| if (elementName.equals("support-classes")) { | |||||
| supportClasses = new FileSet(); | |||||
| return supportClasses; | |||||
| } | |||||
| return null; | |||||
| } | |||||
| /** | /** | ||||
| * Set the srcdir attribute. The source directory is the directory that contains | * Set the srcdir attribute. The source directory is the directory that contains | ||||
| * the classes that will be added to the EJB jar. Typically this will include the | * the classes that will be added to the EJB jar. Typically this will include the | ||||
| @@ -301,7 +316,7 @@ public class EjbJar extends MatchingTask { | |||||
| if (srcDir == null) { | if (srcDir == null) { | ||||
| throw new BuildException("The srcDir attribute must be specified"); | throw new BuildException("The srcDir attribute must be specified"); | ||||
| } | } | ||||
| if (deploymentTools.size() == 0) { | if (deploymentTools.size() == 0) { | ||||
| GenericDeploymentTool genericTool = new GenericDeploymentTool(); | GenericDeploymentTool genericTool = new GenericDeploymentTool(); | ||||
| genericTool.setDestdir(destDir); | genericTool.setDestdir(destDir); | ||||
| @@ -335,14 +350,13 @@ public class EjbJar extends MatchingTask { | |||||
| log(files.length + " deployment descriptors located.", | log(files.length + " deployment descriptors located.", | ||||
| Project.MSG_VERBOSE); | Project.MSG_VERBOSE); | ||||
| // Loop through the files. Each file represents one deployment | // Loop through the files. Each file represents one deployment | ||||
| // descriptor, and hence one bean in our model. | // descriptor, and hence one bean in our model. | ||||
| for (int index = 0; index < files.length; ++index) { | for (int index = 0; index < files.length; ++index) { | ||||
| // process the deployment descriptor in each tool | // process the deployment descriptor in each tool | ||||
| for (Iterator i = deploymentTools.iterator(); i.hasNext(); ) { | for (Iterator i = deploymentTools.iterator(); i.hasNext(); ) { | ||||
| EJBDeploymentTool tool = (EJBDeploymentTool)i.next(); | EJBDeploymentTool tool = (EJBDeploymentTool)i.next(); | ||||
| tool.processDescriptor(files[index], saxParser); | |||||
| tool.processDescriptor(files[index], saxParser, supportClasses); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -264,7 +264,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||||
| if (!addedfiles.contains(logicalFilename)) { | if (!addedfiles.contains(logicalFilename)) { | ||||
| iStream = new FileInputStream(inputFile); | iStream = new FileInputStream(inputFile); | ||||
| // Create the zip entry and add it to the jar file | // Create the zip entry and add it to the jar file | ||||
| ZipEntry zipEntry = new ZipEntry(logicalFilename); | |||||
| ZipEntry zipEntry = new ZipEntry(logicalFilename.replace('\\','/')); | |||||
| jStream.putNextEntry(zipEntry); | jStream.putNextEntry(zipEntry); | ||||
| // Create the file input stream, and buffer everything over | // Create the file input stream, and buffer everything over | ||||
| @@ -301,7 +301,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||||
| return new DescriptorHandler(srcDir); | return new DescriptorHandler(srcDir); | ||||
| } | } | ||||
| public void processDescriptor(String descriptorFileName, SAXParser saxParser) { | |||||
| public void processDescriptor(String descriptorFileName, SAXParser saxParser, | |||||
| FileSet supportFileSet) { | |||||
| FileInputStream descriptorStream = null; | FileInputStream descriptorStream = null; | ||||
| try { | try { | ||||
| @@ -315,7 +316,20 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||||
| saxParser.parse(new InputSource(descriptorStream), handler); | saxParser.parse(new InputSource(descriptorStream), handler); | ||||
| Hashtable ejbFiles = handler.getFiles(); | Hashtable ejbFiles = handler.getFiles(); | ||||
| // add in support classes if any | |||||
| if (supportFileSet != null) { | |||||
| Project project = task.getProject(); | |||||
| File supportBaseDir = supportFileSet.getDir(project); | |||||
| DirectoryScanner supportScanner = supportFileSet.getDirectoryScanner(project); | |||||
| supportScanner.scan(); | |||||
| String[] supportFiles = supportScanner.getIncludedFiles(); | |||||
| for (int i = 0; i < supportFiles.length; ++i) { | |||||
| ejbFiles.put(supportFiles[i], new File(supportBaseDir, supportFiles[i])); | |||||
| } | |||||
| } | |||||
| String baseName = ""; | String baseName = ""; | ||||
| // Work out what the base name is | // Work out what the base name is | ||||