simple.page.ant
Class CompileTask

java.lang.Object
  extended by Task
      extended by simple.page.ant.CompileTask

public class CompileTask
extends Task

The CompileTask represents an Ant task definition that can be used within an Ant build file to compile JSP templates. This offers the ability to use pre-compiled JSP templates with the template engine. Compiling the templates before starting the server ensures that an initial delay on requesting a page is not incurred. To add this task to your Ant build the following can be used.

 
 <taskdef name="jspc" classname="simple.page.ant.CompileTask"/>
 
 
This declares a task named "jspc" which can be used within the Ant build.xml file to compile JSP sources. Typically you will have to add a classpath to the taskdef declaration so that it knows where to load the CompileTask byte code.

Once the task definition has been declared you will need to create a task execution configuration block. The following is an example of how to write a JSP compilation task. In the configuration below the "build" parameter is where sources and classes will be compiled to. The "project" parameter specifies the root package name used.

 
    <jspc build="${home}/WEB-INF" project="test">
       <source dir="${home}">
          <include name="**/*.jsp"/>
       </source>
       <classpath>
          <fileset dir="${lib}">
             <include name="**/*.jar"/>
       </fileset>
       </classpath>
    </jspc>

 
To ensure that your JSP sources compile, you will need to add a classpath to the compiler. The classpath used has the same format of a typical Ant classpath element. Finally, the source element is used to specify the directory the source files are read from as well as the source files to include, this is an Ant "fileset".

Author:
Niall Gallagher

Constructor Summary
CompileTask()
           
 
Method Summary
 void addSource(FileSet source)
          This is used to set the configuration for the source files to build.
 Path createClasspath()
          This is used to create a classpath element from the Ant task.
 void execute()
          This is used to execute the compile step.
 void execute(java.io.File path, java.lang.String[] list)
          This is used to execute the compile step.
 void setBuild(java.io.File build)
          This is used to collect the build directory, which is where the JSP source files are translated and compiled to.
 void setClasspath(Path path)
          This is used to set the classpath from an attribute.
 void setProject(java.lang.String project)
          This is used to specify the name of the JSP workspace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompileTask

public CompileTask()
Method Detail

setClasspath

public void setClasspath(Path path)
This is used to set the classpath from an attribute. This will either complement the classpath element used in the compile block or act as the sole classpath used to compile the sources.

Parameters:
path - this is the classpath specified in the Ant task

addSource

public void addSource(FileSet source)
               throws BuildException
This is used to set the configuration for the source files to build. This is an Ant "fileset" and contains a directory as well as a collection of included and excluded sources. This is typically given a pattern such as "*.jsp" to match JSP files.

Parameters:
source - this is the file set for matching JSP sources
Throws:
BuildException

createClasspath

public Path createClasspath()
This is used to create a classpath element from the Ant task. This is used if there are multiple JAR files to be used in the classpath or if a simple classpath attribute is not sufficient.

Returns:
this returns a path, which will be given the classpath

setBuild

public void setBuild(java.io.File build)
This is used to collect the build directory, which is where the JSP source files are translated and compiled to. This is typically a WEB-INF directory within the source directory.

Parameters:
build - this is the directory to compile JSP sources to

setProject

public void setProject(java.lang.String project)
This is used to specify the name of the JSP workspace. This is used by the workspace to set a root package name for all of the translated and compiled sources. This is useful when there are multiple sources compiled into the same build directory.

Parameters:
project - this is the root package for the sources

execute

public void execute()
             throws BuildException
This is used to execute the compile step. This will locate all the sources specified within the source element and transform them to URI paths, so that the cam be used by the translation and compilation tools for the JSP template framework.

Throws:
BuildException - if there is a problem compiling

execute

public void execute(java.io.File path,
                    java.lang.String[] list)
             throws java.lang.Exception
This is used to execute the compile step. This will locate all the sources specified within the source element and transform them to URI paths, so that the cam be used by the translation and compilation tools for the JSP template framework.

Parameters:
path - this is the path to locate the JSP sources from
list - this is a list of URI paths for the JSP targets
Throws:
java.lang.Exception - if there is a problem compiling sources