java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Ant arrow How to use Available task
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4092
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use Available task E-mail
User Rating: / 8
PoorBest 

Available

Description

Sets a property if a resource is available at runtime. This resource can be a file, a directory, a class in the classpath, or a JVM system resource.

If the resource is present, the property value is set to true by default; otherwise, the property is not set. You can set the value to something other than the default by specifying the value attribute.

Normally, this task is used to set properties that are useful to avoid target execution depending on system parameters.

Parameters

Attribute Description Required
property The name of the property to set. Yes
value The value to set the property to. Defaults to "true". No
classname The class to look for in the classpath. Yes
file The file to look for.
resource The resource to look for in the JVM.
classpath The classpath to use when looking up classname or resource. No
filepath The path to use when looking up file. No
classpathref The classpath to use, given as a reference to a path defined elsewhere. No
type The type of file to look for, either a directory (type="dir") or a file (type="file"). If not set, the property will be set if the name specified in the file attribute exists as either a file or a directory. No
ignoresystemclasses Ignore Ant's runtime classes, using only the specified classpath. Only affects the "classname" attribute. Defaults to "false" No

Parameters specified as nested elements

classpath

Available's classpath attribute is a path-like structure and can also be set via a nested <classpath> element.

filepath

Available's filepath attribute is a path-like structure and can also be set via a nested <filepath> element.

Examples

<available classname="org.whatever.Myclass" property="Myclass.present"/>

sets the Myclass.present property to the value "true" if the class org.whatever.Myclass is found in Ant's classpath.

<property name="jaxp.jar" value="./lib/jaxp11/jaxp.jar"/>
<available file="${jaxp.jar}" property="jaxp.jar.present"/>

sets the jaxp.jar.present property to the value "true" if the file ./lib/jaxp11/jaxp.jar is found.

<available file="/usr/local/lib" type="dir"

           property="local.lib.present"/>

sets the local.lib.present property to the value "true" if the directory /usr/local/lib is found.

...in project ...
<property name="jaxp.jar" value="./lib/jaxp11/jaxp.jar"/>
<path id="jaxp" location="${jaxp.jar}"/>
...in target ...

<available classname="javax.xml.transform.Transformer"
           classpathref="jaxp" property="jaxp11.present"/>

sets the jaxp11.present property to the value "true" if the class javax.xml.transform.Transformer is found in the classpath referenced by jaxp (in this case, ./lib/jaxp11/jaxp.jar).

<available property="have.extras" resource="extratasks.properties">

  <classpath>
    <pathelement location="/usr/local/ant/extra.jar" />
  </classpath>
</available>

sets the have.extras property to the value "true" if the resource-file extratasks.properties is found.

Source: Apache Ant


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.