Integrated ant programming in Eclipse Configuration Chapter

Source: Internet
Author: User
Tags format file system modify variables variable versions window
Programming Summary: This article will show you how to use Eclipse to set the property values and environment variables used by ant, and briefly analyze how to configure the ant editor to manipulate ant files from within Eclipse.

   First, modify Ant Classpath

When using an optional or customized task, you may need to add other libraries to the classpath. To do this, you can modify ant classpath either globally or by using a separate project startup configuration. To set up ant classpath for a separate Eclipse project, open the ant boot Configuration for the project and click the Classpath selection card, and then click the "Add External JARs" button to add the external jar file.

You can modify the ant classpath in a global way to apply it to all projects. To do this, you can choose "Window→preferences→ant→runtime" and click on the "Classpath" tab. In this case, you can add the jar file as needed, and the settings made in this way can be used for all ant builds.

   second, set the property value

You can set the global Ant property by using the Ant Preferences page ("Window→preferences→ant→runtime" and clicking on the "Properties" tab) to open it. To add a new attribute, click the "Add Property" button, and then fill in the name and Value fields in the dialog box that appears. As a result, global properties are set for all ant builds in Eclipse, and because properties are immutable, you set the final values for those properties.

You can set up the project's ant startup configuration to make property settings for each project. To do this, you can click the Properties tab in the boot configuration (see Figure 1), deselect the use global properties as specified in the Ant Runtime preferences check box, and click the "Add Property button to set the new properties.


Figure 1. Setting properties

   third, set environment variables

You can set the environment variables that you want to pass to ant, but you have to make sure that Ant runs in its own JRE (by default). In the project's Ant boot Configuration, tap the "JRE" tab and tap the "separate JRE" radio button. To set the environment variable, click on the "Environment" tab (shown in Figure 2) and click the "New" button to create a new environment variable.


Figure 2. Setting Environment variables

When you click the "New" button, the "New Environment Variable" dialog box appears. Then, enter the name and value of the environment variable in the appropriate domain, and click OK.

   Iv. Configuring the Ant editor

You can reformat an ant build file by using the Format command (ctrl-shift-f) in the Ant Editor context menu or by selecting the "Edit→format" command. To do this, you can open the Ant Preferences page by "Window→preferences→ant→editor→formatter", as shown in Figure 3. Any changes you make will be reflected in the preview box.


Figure 3. Configuring the Ant format


Choose "Window→preferences→ant→editor" to allow you to configure the build File Editor (set tab width, boundary area, highlight, etc.).

  V. Add new ant Tasks and types

You can add new ant tasks and types to eclipse by using the "Ant Preferences" page in "Window→preferences→ant→runtime". These tasks and types can be used in future build files without the use of Taskdef or typedef tasks (which are typically required).

To add a new task, select the Tasks tab shown in Figure 4, click the ADD Task button, and navigate to the jar file where the new ant task resides. To add a new type, click on the "Types" tab and follow the same steps as you did just now.


Figure 4. Add Ant Task

   tip: If you can't find the jar files you need, you should first add them to your ant classpath.

As a choice, you can add other classes that define tasks and types to ant classpath by clicking the Classpath tab.

   six, using different versions of Ant

An ant 1.6.1 is released with Eclipse, but other versions are available. To do this, you can select "Window→preferences→ant→runtime" and click on the Classpath tab to open the Ant Preferences page.

When eclipse runs Ant, it looks for the appropriate class in Ant's Classpath-consistent with the settings set in Ant Home Entries. To change the ant home Entries, just click the Ant Home button and select the ant installation you want to use.

   Tip If you don't want to change classpath, you can run ant as an external tool from eclipse. To do this, you simply choose "run→external tools→external Tools" to open the External Tools dialog box, click Program, and then click the New button to enter a name for the tool (for example, "Ant 1.8" or any other appropriate name). Next, go to the "Location" field, click the "Browse File System" button and navigate to ant.sh or Ant.bat (depending on your operating system) and click "Open." The External Tools dialog box appears, and any parameters you want to pass to Ant are entered in the Arguments field. Finally, in the Working directory field, enter the directory where you want to use the build file and click "Run" to start the new version of Ant. The problem with doing this is that when you work in eclipse, you can't easily access the predefined values that you have. In summary, in most cases, it is better to use ant from within Eclipse when building eclipse Engineering.

   Seven, using the Ant view

An ant view is provided in the release of Eclipse-it is actually a window (it can give you a summary of the goals in the build file). To open this view, select Window→show view→ant, and the Ant view appears to the right of Figure 5.


Figure 5. Ant View

The toolbar in this view contains the following buttons (left to right):

· "Add Build Files"

· "Add build Files with Search"

· "Hide Internal Targets"

· "Run the Default Target"

· "Remove Selected Build File"

· "Remove All Build Files"

To add the build file to the Ant view, click the "Add Build Files" button to open the Choose Location dialog box. From the left side of the container, select the Eclipse project you want to use, and from the right, select the build file you want to add to the ant view. Then, click OK to add the build file to the ant view.

   tip under Windows, you can add a build file to your ant view by dragging and dropping it.

In addition to showing you the profile of a build file, the ant view allows you to run the build file. Select a build file from Ant View and click on the "Run the Default Target" button. Or right click on a target and choose Run from the context menu that appears. Double-clicking a build file in the Ant view opens the build file in the Ant editor (this is the same as right-clicking the build file and selecting the "Open with→ant Editor" effect).

   Viii. Summary

In short, using Ant with Eclipse is a very promising combination. Eclipse allows you to develop and debug your code, and ant lets you easily build and release projects. And both of these tools are free to download, so I'm particularly recommended to use them in combination.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.