You have an Ant build file, and you want to build your application.
Right-click the build file, click Run Ant, choose the Ant target(s) to execute, and click Run.
You created a build.xml file for an Eclipse project in the previous recipe; to run that file in the version of Ant that comes with Eclipse, right-click build.xml, and click Run Ant. Doing so displays the AntProject build.xml dialog shown in Figure 7-4. You can see the Ant targets created there with the default Build target already selected. You can select targets to run independently, but in this case just leave Build selected, and click Run to execute all the targets in the build file and build the project.
Figure 7-4. Running Ant
The results appear in Eclipse in Figure 7-5. Note the message we made Ant echo to the Console view here, Ant is building your project ., followed by the message BUILD SUCCESSFUL .
Figure 7-5. A successful Ant build
Here's the text that appears in the Console view as Ant executes each target:
Buildfile: D:\eclipse212\eclipse\workspace\AntProject\build.xml Initialization: [delete] Deleting directory D:\eclipse212\eclipse\workspace\AntProject\bin [mkdir] Created dir: D:\eclipse212\eclipse\workspace\AntProject\bin [mkdir] Created dir: D:\eclipse212\eclipse\workspace\AntProject\bin\lib Compilation: [javac] Compiling 1 source file to D:\eclipse212\eclipse\workspace\AntProject\bin [javac] Compiled 22 lines in 381 ms (57.7 lines/s) [javac] 1 .class file generated Jar: [jar] Building jar: D:\eclipse212\eclipse\workspace\AntProject\bin\lib \AntProject.jar Build: [echo] Ant is building your project. BUILD SUCCESSFUL Total time: 922 milliseconds
If you switch to the Navigator view, you can see the new lib directory containing the .jar file, AntProject.jar , as shown in Figure 7-6.
Figure 7-6. The new .jar file
184.108.40.206 Eclipse 3.0
By default in Eclipse 3.0, Ant executes in the JVM that is running Eclipse. That means you don't have to set the build.compiler property, as we have in this example, to use the same JVM as Eclipse is using. In Eclipse 3.0, you can set what JVM Ant should use when by right-clicking build.xml, clicking the JRE tab, and then clicking Run Ant.
7.2.4 See Also
Chapter 5 of Eclipse (O'Reilly).