Working with Ant

Ant support is provided as a built-in feature of the workbench. If you right-click any XML file and select Run Ant from the pop-up menu, the Execute Ant Script dialog shows the available Ant targets. You can check, in sequence, which ones are to be executed, and the execution sequence will be shown beside each target. You can also select Display execution log to Ant console, which will cause any Ant messages to be displayed in the Ant Console view (Window > Show view > Other > Ant > Ant Console).

In addition, an Arguments field lets you pass arguments, such as -verbose, to the Ant program. If the Ant script invokes the Ant javac task, then a special -Dbuild.compiler=org.eclipse.pde.internal.core.JDTCompilerAdapter argument must be passed or you will get a Cannot use classic compiler error.

If you use the deprecation="on" option for the javac Ant task, the Rational® Software Development Platform will crash. You should either specify nothing or use deprecation="off".

  1. Create the following echo.xml file inside any project in your workspace:
    <?xml version="1.0"?>
       <project name="Echo" default="echo" basedir=".">
          <target name="echo">
             <echo message="HELLO from echo"/>
          </target>
          <target name="dir">
             <echo message="dir of ${basedir}:"/>
             <exec dir="${basedir}" executable="cmd.exe">
                <arg line="/c dir"/>
             </exec>
          </target>
       </project>
  2. Right-click echo.xml and select Run Ant.
  3. The Run Ant dialog shows that you have two targets, echo and dir, and that echo[1] is the default target that will be executed. If you also select dir, it will change to dir[2] and it will be run as the second target. Ensure that Display execution log to Ant console is checked and click Finish. The script will then be run. The results are displayed in the Ant Console.
  4. Right-click echo.xml and select Run Ant to run it again. This time enter -verbose in the arguments entry field, then click Finish.
Try editing your echo.xml file to include the following bad target with a nonexistent task propertyBad:
<target name="bad">
   <propertyBAD name="MyName" value="MyValue"/>
</target>

Right-click echo.xml and select Run Ant to run it again. Select bad as your target and click Finish. You will receive the following error message, listed twice: "Could not create task of type: propertyBad" in the Problems view. You can partly fix this by changing propertyBad to property, and then saving echo.xml. The errors in the Task view will remain, because the errors are Ant runtime errors. If you run Ant again, the error messages will disappear.


Feedback