Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Workbench User Guide
Previous Page Home Next Page

Editing Ant buildfiles

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.

  1. Create an Ant buildfile called HelloWorld.xml.
  2. Open the Ant editor on the file by selecting Open With > Ant Editor from the file's context menu.
    Note: The default editor for a .xml file is a simple text Opens the File Associations preference page Window > Preferences > General > Editors >File Associations preference page.
  3. Enter the following content in the editor:
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="Hello World" default="Hello" basedir="."> 
      <property name="HelloText" value="Hello"/>
      <target name="Hello">
        <echo>${HelloText}</echo>
      </target>
    </project>
    

    HelloWorld.xml file content

  4. Notice the syntax coloring for property values.
  5. Begin to enter a second target by typing <tar, then hit Ctrl-Space 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.
  6. Name this target World.
  7. Enter an echo task for this target similar to that for the Hello target, but change the text to ${WorldText}.
  8. Add a dependency on the World target from the Hello target. Place the cursor after the definition of the name attribute, hit Ctrl-Space and select the depends attribute completion. Hit Ctrl-Space again to get the completion for the other target World in the buildfile.
  9. Save the buildfile contents.
  10. The full content will now be:
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="Hello World" default="Hello" basedir=".">
      <property name="HelloText" value="Hello"/>
      <property name="WorldText" value="World"/>
      <target name="Hello">
        <echo>${HelloText}</echo>
      </target>
    
      <target name="World">
        <echo>${WorldText}</echo>
      </target>
      </project>
    
  11. Save the changes to HelloWorld.xml.
  12. 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.

    Outline view for an Ant buildfile

  13. 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 view to the next visible entry beginning with that character.
  14. 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.

    Code assist in Ant editor
  15. Close the editor and do not save changes.

Related tasks
Creating Ant buildfiles
Running Ant buildfiles
Saving & Reusing Ant options
Running Ant buildfiles
Creating a project builder Ant buildfile
Ant buildfiles as project builders
Executing project builders
External tools
Non-Ant project builders
Stand-alone external tools


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire