## Using JProfiler With Ant |

| Integrating JProfiler with your ant script (read about ant at ant.apache.org) is easy. Just use the `profile` task that is provided in `{JProfiler installation directory}/bin/ant.jar` instead of the `java` task. The profile task drop in replacement for the the `java` as it supports all its attributes and nested tasks. In addition, it has a number of additional attributes that govern how the application is profiled. Note: At least ant 1.6.3 is required for the profile task to work. To make the `profile` task available to ant, you must first insert a `taskdef` element that tells ant where to find the task definition. Here is an example of using the task in an ant build file:
          <taskdef name="profile"
                   classname="com.jprofiler.ant.ProfileTask"
                   classpath="C:\Program Files\jprofiler4\bin\ant.jar"/>

          <target name="profile">
            <profile classname="MyMainClass" offline="true" sessionid="80">
              <classpath>
                <fileset dir="lib" includes="*.jar" />
              </classpath>
            </profile>
          </target>
The `taskdef` definition must occur only once per ant-build file and can appear anywhere on the top level below the `project` element. Note: it is not possible to copy the `ant.jar` archive to the `lib` folder of your ant distribution. You have to reference a full installation of JProfiler in the task definition.

| Besides the attributes of the `java` task, the `profile` task supports the following additional attributes:
Attribute | Description | Required
--- | --- | ---
offline | Whether the profiling run should be in offline mode. Corresponds to the offline library parameter. Either `true` or `false`. | No, offline and nowait cannot both be `true`
nowait | Whether profiling should start immediately or whether the profiled JVM should wait for a connection from the JProfiler GUI. Corresponds to the nowait library parameter. Either `true` or `false`.
sessionid | Defines the session id from which profiling settings should be taken. Has no effect if neither nowait nor offline are set because in that case the profiling session is selected in the GUI. Corresponds to the id library parameter. | Required if nowait or offline are set.
configfile | Defines the config file from which the profiling settings should be read. If not set or empty, the default config file location will be taken ($HOME/.jprofiler5/config.xml). Has no effect if neither nowait nor offline are set because in that case the profiling session is selected in the GUI. Corresponds to the config library parameter. | No
port | Defines the port number on which the profiling agent should listen for a connection from the JProfiler GUI. This must be the same as the port configured in the remote session configuration. If not set or zero, the default port (8849) will be used. Has no effect if offline is set because in that case there's no connection from the GUI. Corresponds to the port library parameter. | No
usejvmpifor15 | Use the deprecated JVMPI interface for 1.5 JREs. Either `true` or `false`. Default is `false` which means that the new JVMTI interface will be used. | No
useinterpreted | Profile in interpreted mode. Either `true` or `false`. Default is `false`. | No