Java Tutorial/Ant/Resource File — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 15:31, 31 мая 2010

Properties file priority

<?xml version="1.0"?>
<project name="Apache Ant Properties Project" basedir=".">
  

  <property file="build.properties"/>
  <property file="build.properties.default"/>
  <property name="property.example" value="Global"/>
  <target name="print-global">
    <echo message="In print-global"/>
    <echo message="The value of property.example is: ${property.example}"/>
  </target>

  <target name="print-target" depends="print-global">
    <property name="property.example" value="Target"/>
    <echo message="In print-target"/>
    <echo message="The value of property.example is: ${property.example}"/>
  </target>
  
  <target name="print-file" depends="print-target">
    <property name="property.file.example" value="build.xml"/>
    <echo message="In print-file"/>
    <echo>
      The value of property.file.example is: ${property.file.example}
    </echo>
  </target>  
</project>


File: build.properties
property.example=Local File
property.file.example=build.properties

File: build.properties.default
property.example=Default File
property.file.example=build.properties.default





Resource file base properties

<?xml version="1.0"?>
<project name="Apache Ant Properties Project" basedir=".">
  
  <target name="properties.resourcefile">
    <!--
    <property resource="build.res.properties" classpath="./lib"/>
    -->
    <property resource="build.res.properties">
      <classpath path="./lib"/>
    </property>
    <path id="build.classpath.id">
      <pathelement path="${build.classpath}"/>
    </path>
    <property name="build.classpath.property" refid="build.classpath.id"/>
    <echo message="Server URL: ${server.url}"/>
    <echo message="Build classpath: ${build.classpath}"/>
    <echo message="Build classpath converted: ${build.classpath.property}"/>
  </target>
</project>





URL based properties file

<?xml version="1.0"?>
<project name="Apache Ant Properties Project" basedir=".">
  
  <target name="properties.url">
    <property url="http://localhost:8080/properties/build.properties"/>
    <path id="build.classpath.id">
      <pathelement path="${build.classpath}"/>
    </path>
    <property name="build.classpath.property" refid="build.classpath.id"/>
    <echo message="Server URL: ${server.url}"/>
    <echo message="Build classpath: ${build.classpath}"/>
    <echo message="Build classpath converted: ${build.classpath.property}"/>
  </target>
</project>