Ant Task

InfraRED ships with an Ant task that can be used for preparing an application. This is useful largely to use InfraRED with offline (compile-time) weaving. It is recommended that you try using this only after you have sucessfully used it with AspectWerkz load-time weaving as described in the installation page.

The usage of the ant task might look like:

    
<project ..>
  ..

    <taskdef name="infrared" classname="net.sf.infrared.tools.ant.InfraRedTask">
        <classpath>
            <pathelement location="infrared-ant-XX.jar"/>            
        </classpath>
    </taskdef>

    <infrared system="aw" offline="true" server="tomcat" agentConfiguration="infrared-agent.properties">
        <war src="my.war" dest="my.instrumented.war">
            <include name="WEB-INF/classes/**"/>
            <exclude name="WEB-INF/classes/do/not/instrument/**"/>
        </war>
    
        <ear src="my.ear" dest="my.instrumented.ear">
            <module name="ejb-module" type="ejb">
                <include name="**/*.class"/>
                <exclude name="do/not/instrument/**"/>
            </module>
        
            <module name="web-module" type="war">
                <include name="WEB-INF/classes/**"/>
                <exclude name="WEB-INF/classes/do/not/instrument/**"/>
            </module>
        </ear>
    
        <aspectpath>
            <pathelement location="${myaspects.dir}"/>
        </aspectpath>
    
        <extraclasspath>
            <pathelement location="${j2ee.jar}"/>
        </extraclasspath>
    </infrared>
    ..
</project>
 
            

Configuring the Ant Task

The task supports the following configuration attributes:

Attribue Description Default Value
systemaj|aw|aspectwerkz|aspectj. Specifies what aspect system to use.aspectwerkz
offlinetrue|false. Specifies whether aspects should be weaved into the classes prior to deployment or at load-time.true
servertomcat|jboss|weblogic. Specifies which server the application is to be deployed on. Mandatory attribute.-
agentConfigurationThe location of the properties file that would be used to configure InfraRED. The name of this file should be infrared-agent.properties. Mandatory attribute.-
applicationNameThe name of the application. Is needed only when server is Jbossunknown-app
applicationPortThe port of the application. Is needed only when server is Jboss.0

The ant task can take additional inputs using nested war, ear, aspectpath and extraclasspath tags. These are described in the subsequent sections.

Specifying applications

The ant task can take nested war and ear tags which specifies the applications to instrument. Their attributes are desribed below.

  • War tag

    <war> tag specifies a WAR web application. It can take nested includes and excludes tags which specify what portion of the war needs instrumentation. If neither includes or excludes is specified nothing gets instrumented. Attributes of the war tag are described below:

    Attribue Description Default Value
    srcSpecifies the source of the war application. This can be file or a directory (exploded wars).Mandatory attribute.-
    destSpecifies the destination of the instrumented war application. If 'src' was an exploded war, the output would be an exploded war, else it would be a compressed war file. Mandatory attribute.-

    Example:

        
    <war src="my.war" dest="my.instrumented.war">
        <include name="WEB-INF/classes/**"/>
        <exclude name="WEB-INF/classes/do/not/instrument/**"/>
        <include name="WEB-INF/lib/*.jar"/>
        <exclude name="WEB-INF/lib/log4j*.jar"/>
    </war>
                             
                        
  • Ear tag

    <ear> tag specifies an EAR application. It can take nested <module> tags which specify which portions of the archive should be instrumented. If no modules are specified nothing gets instrumented. Attributes of the ear tag are described below:

    Attribue Description Default Value
    srcSpecifies the source of the ear application. This can be file or a directory (exploded wars).Mandatory attribute.-
    destSpecifies the destination of the instrumented ear application. If 'src' was an exploded ear, the output would be an exploded ear, else it would be a compressed war file. Mandatory attribute.-

    The <module> tag identifies a module with an ear, and is very similar to <war> tag

    , except that it has a name attribute instead of src and dest attributes which <war> has. The name attribute identifies the name of the module within an ear. <module> tag also supports a type attribute, the legal values of which are ejb, java, war, classes and jar.
    Attribue Description Default Value
    nameSpecifies the name of the module within an ear. Mandatory attribute.-
    typeejb|java|war|classes|jar. Specifies the type of the module. ejb = ejb module java = java module war = web module classes = directory of classes jar = a jar file Mandatory attribute.-
    Again like <war>, you can provide nested includes and excludes tags which specify what portion of a moudle needs instrumentation

    Example:

        
    <ear src="my.ear" dest="my.instrumented.ear">
        <module name="ejb-module" type="ejb">
            <include name="**/*.class"/>
            <exclude name="do/not/instrument/**"/>
        </module>
            
        <module name="web-module" type="war">
            <include name="WEB-INF/classes/**"/>
            <exclude name="WEB-INF/classes/do/not/instrument/**"/>
        </module>    
        
        <module name="APP-INF/classes" type="classes">
            <include name="**/*.class"/>        
        </module>    
    </war>
                             
                        

Specifying aspects and classpath

Aspects are specified using the <aspectpath> tag. This is a regular Ant <path> tag. This path should refer to the compiled aspect classes. When using AspectWerkz system, you might need to have a META-INF/aop.xml file also in this path. The aspect classes specified by this path would be copied into the appropriate location within the application.

Often you might needs some classes that is needed for compilation, but are not packaged withing the application itself - for example, the jars containing J2EE classes. These needs to be specified using the <extraclasspath> tag. The classes in this path will be used for aspect compilation, but will not be copied into the application.

The aspects that are shipped with InfraRED are packaged in INFRARED_HOME/infrared-agent-all-servlet-2.4.1.BETA.jar. If you need offline process you application to using these, add them as part of the <extraclasspath>. We dont need to copy these into the application because they are available in the server's classpath.

Preserving the working directory

The Ant task uncompresses your application archive into a working directory, and deletes this directory when the task finishes execution. Sometimes you might want to inspect this directory to debug issues you might run into with the Ant task. In that case, enabling the system propery infrared.dont.clean preserves the working directory.

Deploying the aspected ear/war

After the Infrared integrated ear/war is created, the following steps need to be done before you start the server and deploy the applicaton.

Weblogic

  1. Copy the INFRARED_HOME/infrared-agent-all-weblogic-2.4.1.BETA.jar and INFRARED_HOME/infrared-aspectsystem-all-2.4.1.BETA.jar from the infrared release, to a folder (typically in your ${bea-home}/weblogic81/server/ext folder) and include these three jars in your Weblogic server classpath. This can be acheived by specifying the jars in the classpath setting of the startWebLogic.cmd file.
  2. Copy spy.properties file (from %INFRARED_HOME%/props) in a folder (say, bea-home\weblogic81\server\ext\spy) and include this directory in your Weblogic-server classpath, i.e. include this directory in the classpath specified in the startWebLogic.cmd file.
  3. Make a P6Spy connection pool:

    • Create a new connection pool choosing the other option in the driver list
    • Specify com.p6spy.engine.spy.P6SpyDriver as the driver.
    • Specify the Url for the connection. For e.g. the Url for oracle 8i oci driver will be jdbc:oracle:thin:@<db tns name>
    • Make sure real driver property in spy.properties is set to the correct driver. For e.g., for oracle 8i oci driver real driver property should be set to oracle.jdbc.driver.OracleDriver

  4. Point your data-source to the newly created connection-pool.

JBoss

  1. Copy the INFRARED_HOME/infrared-agent-all-jboss-2.4.1.BETA.jar and INFRARED_HOME/infrared-aspectsystem-all-2.4.1.BETA.jar from the infrared release, to folder %JBOSS_HOME%/server/default/lib, which will put these jars in classpath.
  2. Copy spy.properties file (from %INFRARED_HOME%\props) to folder %JBOSS_HOME%/server/default/conf. Folder, %JBOSS_HOME%/server/default/conf is in classpath by default.
  3. Make a P6Spy connection pool:

    • Take the oracle-da.xml for normal jdbc connection pool from %JBOSS_HOME%/docs/examples/jca directory and make following entries :

      <local-tx-datasource>
      <jndi-name>jndi-name</jndi-name>

      <connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>

      <driver-class>com.p6spy.engine.spy.P6SpyDriver</driver-class>

      <user-name>user-name</user-name>

      <password>pswd</password>

      <exception-sorter-class-name> fully-qualified-class-name</exception-sorter-class-name>

      </local-tx-datasource>

    • Put oracle-da.xml in %JBOSS_HOME%/server/default/deploy directory.

Tomcat

  1. Copy the INFRARED_HOME/infrared-agent-all-servlet-2.4.1.BETA.jar and INFRARED_HOME/infrared-aspectsystem-all-2.4.1.BETA.jar from the infrared release, to folder %TOMCAT_HOME%/common/lib/, which will put these jars in classpath.
  2. Copy spy.properties file (from %INFRARED_HOME%/props) to folder %TOMCAT_HOME%\conf and modify the file %TOMCAT_HOME%\bin\setclasspath.bat to set this folder in classpath. Append ;%TOMCAT_HOME%\conf; to the CLASSPATH element.
  3. Modify server.xml to use p6spy driver. Replace the value of parameter 'driverClassName' to com.p6spy.engine.spy.P6SpyDriver.