blob: b9e5dfcb9e6e0b24aa5b84c0df22958b7bdc98a4 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html lang="en">
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2011. 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>
<h1>Editing Ant buildfiles</h1>
<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 <b><a href="../reference/ref-anteditor.htm">Ant editor</a></b>, create a simple Ant buildfile using
this editor.</p>
<ol>
<li>Create an Ant buildfile called <code>HelloWorld.xml</code>.</li>
<li>Open the <b><a href="../reference/ref-anteditor.htm">Ant editor</a></b> 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 <code>.xml</code> file is a simple text
editor until it has buildfile content - which can be changed on the <a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.FileEditors)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the File Associations preference page"><b>General &gt; Editors &gt;File Associations</b></a> preference page.</li>
<li>Enter the following content in the editor:
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project name=&quot;Hello World&quot; default=&quot;Hello&quot; basedir=&quot;.&quot;&gt;
&lt;property name=&quot;HelloText&quot; value=&quot;Hello&quot;/&gt;
&lt;target name=&quot;Hello&quot;&gt;
&lt;echo&gt;${HelloText}&lt;/echo&gt;
&lt;/target&gt;
&lt;/project&gt;
</pre>
<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 <code>&lt;tar</code>, then hit <strong>Ctrl-Space</strong>
to activate content assist. A list of valid completions is presented. Select the <code>&lt;target&gt;</code> 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 <code>World</code>.</li>
<li>Enter an <code>echo</code> task for this target similar to that for the Hello target,
but change the text to <code>${WorldText}</code>.</li>
<li>Add a dependency on the <code>World</code> target from the <code>Hello</code> target. Place the cursor after the definition of the name attribute, hit <strong>Ctrl-Space</strong>
and select the <code>depends</code> attribute completion. Hit <strong>Ctrl-Space</strong> again to get the completion for the other target <code>World</code> in the buildfile.</li>
<li>Save the buildfile contents.</li>
<li>The full content will now be:
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project name=&quot;Hello World&quot; default=&quot;Hello&quot; basedir=&quot;.&quot;&gt;
&lt;property name=&quot;HelloText&quot; value=&quot;Hello&quot;/&gt;
&lt;property name=&quot;WorldText&quot; value=&quot;World&quot;/&gt;
&lt;target name=&quot;Hello&quot;&gt;
&lt;echo&gt;${HelloText}&lt;/echo&gt;
&lt;/target&gt;
&lt;target name=&quot;World&quot;&gt;
&lt;echo&gt;${WorldText}&lt;/echo&gt;
&lt;/target&gt;
&lt;/project&gt;
</pre>
</li>
<li>Save the changes to <code>HelloWorld.xml</code>.</li>
<li>Make the <b><a href="PLUGINS_ROOT/org.eclipse.jdt.doc.user/reference/views/ref-view-outline.htm">Outline view</a></b> visible and notice that there are entries for each
property and each target. In addition, each task under a target has an entry.<br><br>
<img src="../images/outline_hello.png" alt="Outline view for an Ant buildfile" border="0" >
<br><br></li>
<li>Clicking on an entry in the <b><a href="PLUGINS_ROOT/org.eclipse.jdt.doc.user/reference/views/ref-view-outline.htm">Outline view</a></b> will scroll the editor to that
entry. In addition, when the <b><a href="PLUGINS_ROOT/org.eclipse.jdt.doc.user/reference/views/ref-view-outline.htm">Outline view</a></b> has focus, typing a character will
move the selection in the view to the next visible entry beginning with that character.</li>
<li>Position the cursor just past the end of one of the <code>&lt;target&gt;</code> tags,
type <code>&lt;tar</code>, then hit <b>Ctrl-Space</b> to activate content assist. Notice that
now the only valid completions are the <code>&lt;/target&gt;</code> and the <code>tar</code> tag. This is because the Ant editor
knows that nested targets are not allowed.<br><br>
<img src="../images/ant_tar_assist.png" alt="Code assist in Ant editor" border="0">
<br></li>
<li>Close the editor and do not save changes.</li>
</ol>
<h3 class="related">Related tasks</h3>
<a href="qs-82_create.htm">Creating Ant buildfiles</a><br>
<a href="qs-84_run_ant.htm">Running Ant buildfiles</a><br>
<a href="qs-85_ant_configs.htm">Saving &amp; Reusing Ant options</a><br>
<a href="qs-84_run_ant.htm">Running Ant buildfiles</a><br>
<a href="qs-93_project_builder.htm">Creating a project builder Ant buildfile</a><br>
<a href="qs-92_project_builders.htm">Ant buildfiles as project builders</a><br>
<a href="qs-94_run_pj.htm">Executing project builders</a><br>
<a href="qs-95_external_tools.htm">External tools</a><br>
<a href="qs-96_non_ant_pjs.htm">Non-Ant project builders</a><br>
<a href="qs-97_standalone_ets.htm">Stand-alone external tools</a>
</body>
</html>