Home > Articles

Global Concepts

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Predefined Properties

As you've seen already, the property task sets properties that can be referenced later. Ant provides a handful of predefined properties as well as making all the standard Java system properties available. The five Ant-defined properties are

  • basedir—The value that you set in the basedir attribute of the project tag

  • ant.file—The full path name of the build file being executed

  • ant.version—The version of the currently executing Ant instance

  • ant.project.name—The value from the name attribute of the project tag

  • ant.java.version—The version of the Java VM that Ant detected at runtime

You can access any of these properties from your own targets. For example, if you wanted to name a JAR file with the same name as the project, you could write a property as shown in Listing 3.76.

Listing 3.76 Referencing a Predefined Property

<property name="jar.name" value="${ant.project.name}.jar"/>

Similarly, you can get to any property that would be returned by a call to System.getProperties() in your Java code. Some of these properties include:

  • os.name—The operating system Ant is running on

  • os.version—The version of the current operating system

  • java.class.path—The classpath Ant is using

  • user.home—The current user's home directory

Many more system properties are available. Consult the JavaDoc for java.lang.System.getProperties() for the full list.

  • + Share This
  • 🔖 Save To Your Account