| <!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 > 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 > Preferences > General |
| > File Associations</b>. </li> |
| <li>Enter the following content in the editor: <br> |
| <br> |
| <p> <?xml version="1.0" encoding="UTF-8"?></p> |
| |
| <p><project name="Hello World" default="Hello" basedir="."></p> |
| <blockquote> |
| <property name="HelloText" value="Hello"/> |
| <p><target name="Hello"></p> |
| <blockquote> |
| <echo>${HelloText}</echo> |
| </blockquote> |
| </blockquote> |
| <blockquote> |
| </target> |
| </blockquote> |
| <p></project> </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 '<tar', then hit <strong>Ctrl-Space</strong> |
| to activate content assist. A list of valid completions is presented. Select the <target> 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> <?xml version="1.0" encoding="UTF-8"?></p> |
| <br> |
| <p><project name="Hello World" default="Hello" basedir="."></p> |
| <blockquote> |
| <property name="HelloText" value="Hello"/><br> |
| <property name="WorldText" value="World"/> |
| <p><target name="Hello"></p> |
| <blockquote> |
| <echo>${HelloText}</echo><br> |
| </blockquote> |
| <p></target></p> |
| </blockquote> |
| <blockquote> |
| <p><target name="World"></p> |
| <blockquote> |
| <echo>${WorldText}</echo><br> |
| </blockquote> |
| <p></target></p> |
| </blockquote> |
| <p></project> </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 '<target>' tags, |
| type '<tar', then hit Ctrl-Space to activate content assist. Notice that |
| now the only valid completions are the '</target>' 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> |