ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Integrating Ant with Eclipse, Part 1
Pages: 1, 2, 3, 4

Support for Ant is evident in Eclipse's code assist (also called content assist), which was added for Ant build files in Eclipse 3.0. When you enter partial text for Ant elements or attributes, you can press Ctrl-Space to open code assist, which will list possible completions of what you've been typing, as shown in Figure 11-4.



Figure X
Figure 11-4. Using code assist

TIP: If you enter a $ and use code assist, Eclipse's Ant editor will list all the Ant property names it knows about.

Eclipse 3.0 can catch syntax errors in Ant build files. For example, ending a target with </targe>, instead of a </target> tag, is immediately caught by the Eclipse Ant editor, as shown in Figure 11-5. If you let your cursor rest over the circled X icon to the left of the problem line, you'll see Eclipse's explanation of the problem: "Expected `</target>' to terminate element starting on line 3." This kind of syntax checking and corrections alone are worth the price of admission.

Figure X
Figure 11-5. Handling syntax errors

TIP: You can reformat an Ant build file-indenting everything nicely, using the Format command (Ctrl-Shift-F) from the Ant editor's context menu or by selecting Edit→ Format.

Want to see the value of a property? Let the mouse hover over it, and its value will appear in a tooltip.

TIP: Under some circumstances, Eclipse can generate Ant scripts for you. For example, if you're creating an Eclipse plug-in, which extends Eclipse with your own views and editors, you'll use a plug-in manifest file named plugin.xml. If you right-click the manifest file and select the Create Ant Build File item, Eclipse will create a build file for you. If you select Project→ Generate Javadoc, the Javadoc wizard will create an Ant build file that runs the javadoc tool, which you can edit as needed.

Running Ant Build Files

You have two options to run these build files from within Eclipse. You can right-click build.xml in the Package Explorer and select Run→ Ant Build. Doing so runs Ant and gives you the results in Eclipse's Console view.

TIP: Eclipse 3.0 runs Ant in a separate JVM, solving many problems that used to plague previous versions.

The output in the Console view is the same as you'd see from Ant if you ran the build file on the command line:

Buildfile: D:\eclipse3\eclipse\workspace\AntExample\build.xml
compile:
    [javac] Compiling 1 source file
compress:
      [jar] Building jar: D:\eclipse3\eclipse\workspace\AntExample\Project.jar
main:
     [echo] Building the .jar file.
BUILD SUCCESSFUL
Total time: 2 seconds

If there are problems, you can see Ant's output in the Console view. Eclipse will give you a summary in the Problems view, which you can see by clicking the Problems tab at the bottom of Eclipse.

Pages: 1, 2, 3, 4

Next Pagearrow