What is the significance of attribute depends in ant file




















In case your Ant build script contains both targets and properties, it is common but not required that the properties are listed before the targets in the Ant build script. Here is an example of an Ant build script with both an Ant target and an Ant property:. To make an Ant target actually do something you must add some tasks to it. Ant comes with a lot of built-in tasks that can help you do all kinds of things, like creating directories, copy files, compile Java code, generate JavaDoc, create ZIP and JAR files, upload files to servers via SSH, and many, many other tasks.

In this example I will use a simple Ant task named echo. The echo task simply prints a message out to the command prompt. This may sometimes be useful inside larger builds, to give a status of what build work has been carried out.

Here is an example of an Ant target with an echo task inside:. If you run the Ant target firstTarget the echo task will get executed. The echo task as defined here will print out the message "This is version 1. This reference is substituted for the value of the version property before the message is printed.

In its most simple form properties are defined in the buildfile for example by the property task or might be set outside Ant. A property has a name and a value; the name is case-sensitive. Properties may be used in the value of task attributes or in the nested text of tasks that support them.

Since Ant 1. Notice that we are declaring properties outside any target. When you do this they are evaluated before any targets are executed. We have given some targets descriptions; this causes the -projecthelp invocation option to list them as public targets with the descriptions; the other target is internal and not listed.

Finally, for this target to work the source in the src subdirectory should be stored in a directory tree which matches the package names. A project can have a set of tokens that might be automatically expanded if found when a file is copied, when the filtering-copy behavior is selected in the tasks that support this.

These might be set in the buildfile by the filter task. This token syntax matches the syntax of other build systems that perform such filtering and remains sufficiently orthogonal to most programming and scripting languages, as well as with documentation systems. Note : If a token with the format token is found in a file, but no filter is associated with that token, no changes take place; therefore, no escaping method is available—but as long as you choose appropriate names for your tokens, this should not cause problems.

Warning : If you copy binary files with filtering turned on, you can corrupt the files. This feature should be used with text files only. Ant will convert the separator to the correct character of the current operating system. Wherever path-like values need to be specified, a nested element can be used. This takes the general form of:. The location attribute specifies a single file or directory relative to the project's base directory or an absolute filename , while the path attribute accepts colon- or semicolon-separated lists of locations.

The bottom line is that when task A references a property declared in task B, care must be taken to ensure that task A is directly or indirectly dependent on task B so that the build order is deterministic and the property will be declared before it is referenced. Properties are immutable once declared. For example, in the following build script:. Unfortunately, multiple assignments are quietly ignored and thus are quite a source of confusion.

Properties are special in that they can be declared outside the scope of a target. A property declared in such a manner is defined before any target is executed and is immutable. Properties can also be declared outside the build script. A property declared on the command line is defined before the build is launched and is immutable. Then, the foo property is assigned its value before the build script is executed, and its value is not changed by the property declaration or property task within the build script.

Declaring a property as part of the Ant command line. Alternatively, properties can be specified by switching to the Properties tab panel see Figure and unchecking the Use global properties as specified in the Ant runtime preferences checkbox.

The top part of the page contains individual property declarations, while the bottom part displays a list of files containing property declarations. Declaring properties and property files applicable to an individual build script. Similar to the Properties tab panel shown earlier, the top part of the preference page contains individual property declarations, while the bottom part displays a list of files that contain the property declarations.

Declaring properties and property files applicable to all build scripts in the workspace. For example, if the following build script is executed:.

The foo property is assigned in the init target and should be immutable see Section Consider the previous build script with a slight modification. This modification makes the sub target dependent on the init target.

When building complex Ant build scripts, you will find groups of similar operations. Another way to group and parameterize operations is to create a new task using a macrodef. For example, modify the script from the previous example to use a macrodef.

The first thing to notice in the script is that calls to the sub macrodef look exactly like calls to a built-in Ant task such as echo. The permitted attributes in that call are specified by the attribute tag as in the following. If the attribute is optional and need not be specified by the caller, then supply a default value for the attribute as in the following. Attributes are resolved in the order that they are defined and before any build properties, leading to some interesting techniques.

First, an attribute defined earlier can be used in the default value of an attribute defined later. Category : Book:Apache Ant. Namespaces Book Discussion. Views Read Edit Edit source View history. Reading room forum Community portal Bulletin Board Help out!



0コメント

  • 1000 / 1000