FileDocCategorySizeDatePackage
JlinkTask.javaAPI DocApache Ant 1.705494Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.jlink

JlinkTask

public class JlinkTask extends org.apache.tools.ant.taskdefs.MatchingTask
This class defines objects that can link together various jar and zip files.

It is basically a wrapper for the jlink code written originally by Patrick Beard. The classes org.apache.tools.ant.taskdefs.optional.jlink.Jlink and org.apache.tools.ant.taskdefs.optional.jlink.ClassNameReader support this class.

For example:

<jlink compress="false" outfile="out.jar"/>
<mergefiles>
<pathelement path="${build.dir}/mergefoo.jar"/>
<pathelement path="${build.dir}/mergebar.jar"/>
</mergefiles>
<addfiles>
<pathelement path="${build.dir}/mac.jar"/>
<pathelement path="${build.dir}/pc.zip"/>
</addfiles>
</jlink>
ant.task
ignore="true"

Fields Summary
private File
outfile
private org.apache.tools.ant.types.Path
mergefiles
private org.apache.tools.ant.types.Path
addfiles
private boolean
compress
Constructors Summary
Methods Summary
public org.apache.tools.ant.types.PathcreateAddfiles()
Establishes the object that contains the files to be added to the output.

return
a path to be configured

        if (this.addfiles == null) {
            this.addfiles = new Path(getProject());
        }
        return this.addfiles.createPath();
    
public org.apache.tools.ant.types.PathcreateMergefiles()
Establishes the object that contains the files to be merged into the output.

return
a path to be configured

        if (this.mergefiles == null) {
            this.mergefiles = new Path(getProject());
        }
        return this.mergefiles.createPath();
    
public voidexecute()
Does the adding and merging.

throws
BuildException on error

        //Be sure everything has been set.
        if (outfile == null) {
            throw new BuildException("outfile attribute is required! "
                + "Please set.");
        }
        if (!haveAddFiles() && !haveMergeFiles()) {
            throw new BuildException("addfiles or mergefiles required! "
                + "Please set.");
        }
        log("linking:     " + outfile.getPath());
        log("compression: " + compress, Project.MSG_VERBOSE);
        jlink linker = new jlink();
        linker.setOutfile(outfile.getPath());
        linker.setCompression(compress);
        if (haveMergeFiles()) {
            log("merge files: " + mergefiles.toString(), Project.MSG_VERBOSE);
            linker.addMergeFiles(mergefiles.list());
        }
        if (haveAddFiles()) {
            log("add files: " + addfiles.toString(), Project.MSG_VERBOSE);
            linker.addAddFiles(addfiles.list());
        }
        try  {
            linker.link();
        } catch (Exception ex) {
            throw new BuildException(ex, getLocation());
        }
    
private booleanhaveAddFiles()

        return haveEntries(addfiles);
    
private booleanhaveEntries(org.apache.tools.ant.types.Path p)

        if (p == null) {
            return false;
        }
        if (p.size() > 0) {
            return true;
        }
        return false;
    
private booleanhaveMergeFiles()

        return haveEntries(mergefiles);
    
public voidsetAddfiles(org.apache.tools.ant.types.Path addfiles)
Sets the files to be added into the output.

param
addfiles a path

        if (this.addfiles == null) {
            this.addfiles = addfiles;
        } else {
            this.addfiles.append(addfiles);
        }
    
public voidsetCompress(boolean compress)
Defines whether or not the output should be compacted.

param
compress a boolean value

        this.compress = compress;
    
public voidsetMergefiles(org.apache.tools.ant.types.Path mergefiles)
Sets the files to be merged into the output.

param
mergefiles a path

        if (this.mergefiles == null) {
            this.mergefiles = mergefiles;
        } else {
            this.mergefiles.append(mergefiles);
        }
    
public voidsetOutfile(java.io.File outfile)
The output file for this run of jlink. Usually a jar or zip file.

param
outfile the output file

        this.outfile = outfile;