|
11.2. 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
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. The other option to run a build file is to right-click build.xml in the Package Explorer and select Run Figure 11-6. Selecting an Ant target![]() By default, the Targets tab is selected in this dialog, showing a list of the targets in build.xml. The default target has been selected; you can click the Run button to run that target, or you can select other targets to run. If you leave the default target selected and click Run, you'll see the same results as before in the Console view. You can set the execution order of targets, shown in the Target execution order box at the bottom of the page (the order in which you select the items is the order in which they will run). Ant will still run each target's dependencies, but you have to be careful in case your changes mess up the overall build order. 11.2.1. Selecting the Build File and Passing Arguments to AntYou can get as much use out of Ant in Eclipse as you can from the command line. For example, to pass arguments to Ant, right-click build.xml in the Package Explorer and select Run Figure 11-7. Setting the build file and arguments to pass to Ant![]()
11.2.2. Modifying the Ant ClasspathWhen using an optional or custom task, adding extra libraries to the classpath may be necessary. The Ant classpath can be modified globally or by using an individual project's launch configuration. To set the Ant classpath for an individual Eclipse project, open the Ant launch configuration for the project and click the Classpath tab. You can add external JARs by clicking the Add External JARs button. You can modify the Ant classpath globally for all projects. To do that, select Window 11.2.3. Setting Property ValuesYou can set global Ant properties using the Ant preferences page, which you open by selecting Window You can set properties on a project-by-project basis by setting the project's Ant launch configuration. Click the Properties tab in the launch configuration (as seen in Figure 11-8), deselect the "Use global properties as specified in the Ant runtime preferences" checkbox, and click the Add Property button to set new properties. Figure 11-8. Setting properties![]() 11.2.4. Setting Environment VariablesYou can set the environment variables you want passed to Ant, but you have to ensure Ant will run in its own JRE (the default). In the project's Ant launch configuration, click the JRE tab and click the Separate JRE radio button. To set environment variables, click the Environment tab, shown in Figure 11-9, and click the New button to create a new environment variable. Figure 11-9. Setting environment variables![]() When you click the New button, the New Environment Variable dialog appears. Enter the name and value of the environment variable in the appropriate fields and click OK. 11.2.5. Configuring the Ant EditorYou can reformat an Ant build file using the Format command (Ctrl-Shift-F) from the Ant editor's context menu or by selecting Edit Figure 11-10. Configuring Ant formatting![]() Selecting Window 11.2.6. Adding New Ant Tasks and Types You can add new Ant tasks and types (covered in detail in the next chapter) to Eclipse by using the Ant preferences page at Window To add a new task, select the Tasks tab, shown in Figure 11-11, click the Add Task button, and navigate to the JAR file in which the new Ant task is located. To add a new type, click the Types tab and follow the same steps. Figure 11-11. Adding Ant tasks![]()
Alternatively, you can add additional classes defining tasks and types to the Ant classpath by clicking the Classpath tab. |
|