blob: 3e0e2d2c1011fdc5724b05a9ab39d30ca43b3577 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2006. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="../book.css" CHARSET="ISO-8859-1" TYPE="text/css">
<title>Editing Ant buildfiles</title>
</HEAD>
<BODY BGCOLOR="#ffffff">
<h3>Editing Ant buildfiles</h3>
<P CLASS="Para">Because Ant buildfiles are simple text files, any text editor
can be used to edit them. But there are several advantages to using the Eclipse
Ant editor, including syntax coloring, content assist, navigation, occurrence marking and an outline view. To
get familiar with the Eclipse Ant editor, create a simple Ant buildfile using
this editor.</P>
<ol>
<li>Create an Ant buildfile called HelloWorld.xml.</li>
<li>Open the Ant editor on the file by selecting <b>Open With &gt; Ant Editor</b>
from the file's context menu. <br>
<strong>Note:</strong> The default editor for a .xml file is a simple text
editor until it has buildfile content, but this can be changed in the <b>Window &gt; Preferences &gt; General
&gt; File Associations</b>. </li>
<li>Enter the following content in the editor: <br>
<br>
<p> &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</p>
<p>&lt;project name=&quot;Hello World&quot; default=&quot;Hello&quot; basedir=&quot;.&quot;&gt;</p>
<blockquote>
&lt;property name=&quot;HelloText&quot; value=&quot;Hello&quot;/&gt;
<p>&lt;target name=&quot;Hello&quot;&gt;</p>
<blockquote>
&lt;echo&gt;${HelloText}&lt;/echo&gt;
</blockquote>
</blockquote>
<blockquote>
&lt;/target&gt;
</blockquote>
<p>&lt;/project&gt; </p>
<p><img src="../images/first_anteditor.png" alt="HelloWorld.xml file content" border="0" ></p>
</li>
<li>Notice the syntax coloring for property values.</li>
<li>Begin to enter a second target by typing '&lt;tar', then hit <strong>Ctrl-Space</strong>
to activate content assist. A list of valid completions is presented. Select the &lt;target&gt; completion and
notice that the editor inserts both the opening and closing tags and leaves
the cursor positioned to enter attributes for this tag.</li>
<li>Name this target 'World'.</li>
<li>Enter an 'echo' task for this target similar to that for the Hello target,
but change the text to '${WorldText}'.</li>
<li>Add a dependency on the 'World' target from the 'Hello' target. Place the cursor after the definition of the name attribute, hit <strong>Ctrl-Space</strong>
and select the depends attribute completion. Hit <strong>Ctrl-Space</strong> again to get the completion for the other target 'World' in the buildfile.</li>
<li>Save the buildfile contents.</li>
<li>The full content will now be:
<br>
<p> &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</p>
<br>
<p>&lt;project name=&quot;Hello World&quot; default=&quot;Hello&quot; basedir=&quot;.&quot;&gt;</p>
<blockquote>
&lt;property name=&quot;HelloText&quot; value=&quot;Hello&quot;/&gt;<br>
&lt;property name=&quot;WorldText&quot; value=&quot;World&quot;/&gt;
<p>&lt;target name=&quot;Hello&quot;&gt;</p>
<blockquote>
&lt;echo&gt;${HelloText}&lt;/echo&gt;<br>
</blockquote>
<p>&lt;/target&gt;</p>
</blockquote>
<blockquote>
<p>&lt;target name=&quot;World&quot;&gt;</p>
<blockquote>
&lt;echo&gt;${WorldText}&lt;/echo&gt;<br>
</blockquote>
<p>&lt;/target&gt;</p>
</blockquote>
<p>&lt;/project&gt; </p></li>
<li>Save the changes to HelloWorld.xml.</li>
<li>Make the Outline view visible and notice that there are entries for each
property and each target. In addition, each task under a target has an entry.<br>
<img src="../images/outline_hello.png" alt="Outline view for an Ant buildfile" border="0" ></li>
<li>Clicking on an entry in the Outline view will scroll the editor to that
entry. In addition, when the Outline view has focus, typing a character will
move the selection in the Outline view to the next visible entry beginning
with that character.</li>
<li>Position the cursor just past the end of one of the '&lt;target&gt;' tags,
type '&lt;tar', then hit Ctrl-Space to activate content assist. Notice that
now the only valid completions are the '&lt;/target&gt;' and the 'tar' tag. This is because the Ant editor
knows that nested targets are not allowed.
<img src="../images/Image602_tar_assist.png" alt="Code assist in Ant editor" border="0">
</li>
<li>Close the editor and do not save changes.</li>
</ol>
</BODY>
</HTML>