简体   繁体   中英

How to use property Array in ant Task?

I have created an Ant task, wherein i would like to have an property array? First of all, is it possible? Does ant allows us to have a property array?

public class MyTask extends Task {
    private String tokens[] = null;
    public void setTokens(String[] _tokens) {
        //...
    }
    public void execute() {
     // iterator over the conditions
    }
}

Now how to set tokens in ant build file?

You sound like you want to set multiple inner tags.

Writing your own task gives some guidelines. The section you are after is Supporting Nested Elements . It is pretty simple. I would be inclined to use something like the following

List tokens = new ArrayList();

public void addConfiguredToken(NestedElement token) {
    tokens.add(token);
}

You could then use it using something like the following

<task>
    <token value="XXX" />
    <token value="YYY" />
</task>

Ant has some types like DirList and FileSet as well - it's quite common to have a task that accepts an attribute that is an implicit list, and then iterate over the contents. If you're dealing with files, what's nice is that you can tell Ant to glob over them, store them in a FileSet, and pass that to your custom type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM